0
사용자가 잠금 화면에서 오디오를 재생할 수 있도록 새로운 ios8 알림 작업을 사용하려고합니다.ios8에서 알림 작업으로 오디오를 재생하는 방법은 무엇입니까?
데이터를 백그라운드에서 다운로드 할 수 있지만 avaudio 플레이어가 재생되지 않는 것 같습니다.
도움이 될 것입니다. 처음에는 와서, 그 배경과 사운드 재생 옵션으로 뭔가를해야합니다 ...
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
//handle the actions
if ([identifier isEqualToString:@"ACCEPT_IDENTIFIER"]){
Message *newMessage = [Message rawMessageToInstance:[userInfo valueForKey:@"message"]];
AVAudioSession* session = [AVAudioSession sharedInstance];
BOOL success; NSError* error;
success = [session setCategory:AVAudioSessionCategoryPlayback
error:&error];
if (!success)
NSLog(@"AVAudioSession error setting category:%@",error);
[session setActive:YES error:nil];
NSLog(@"%lu",newMessage.identifier);
[ApiUtils downloadAudioFileAtURL:[newMessage getMessageURL] success:^void(NSData *data) {
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:data error:nil];
[player setVolume:2];
[player play];
[self performSelector:@selector(completeNotif:) withObject:completionHandler afterDelay:[player duration]];
} failure:^(){
completionHandler();
}];
}
}