【发布时间】:2014-12-23 04:40:22
【问题描述】:
我正在尝试使用新的 ios8 通知操作让用户从锁定屏幕播放音频。
我设法在后台下载数据,但 avaudioplayer 似乎没有播放。
任何帮助将不胜感激!
代码如下:
- (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();
}];
}
}
【问题讨论】:
标签: objective-c push-notification apple-push-notifications ios8