迅速。 接收远程控制事件以与MPNowPLayingInfoCenter一起工作
据我所知,为了在锁屏上显示音乐播放器,只写下面的代码是不够的。
override func viewDidAppear(animated: Bool) { var mpic = MPNowPlayingInfoCenter.defaultCenter() mpic.nowPlayingInfo = [ MPMediaItemPropertyTitle:"This Is a Test", MPMediaItemPropertyArtist:"Matt Neuburg" ] }
我的应用程序也应该能够接收远程控制事件
那么,如何在Swift中做到这一点?
我从Apple文档中find了这个,但是它是针对Objective-C的。
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Turn on remote control event delivery [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; // Set itself as the first responder [self becomeFirstResponder]; } - (void)viewWillDisappear:(BOOL)animated { // Turn off remote control event delivery [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; // Resign as first responder [self resignFirstResponder]; [super viewWillDisappear:animated]; } - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent { if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: [self playOrStop: nil]; break; case UIEventSubtypeRemoteControlPreviousTrack: [self previousTrack: nil]; break; case UIEventSubtypeRemoteControlNextTrack: [self nextTrack: nil]; break; default: break; } } }
刚刚在GitHub上find解决schemehttps://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/bk2ch14p643ducking/ch27p912ducking
- 我如何检查移动数据或无线networking打开或closures。 ios迅速
- 如何将Decimal转换为分隔符后两位数的string?
- swift UIView animateWithDuration重复和自动反向
- Swift iOS:收到远程通知后,Closure不会在后台运行
- 当一个弱引用的对象(任意types)被释放时,我可以挂钩吗?
- Facebook SDK共享链接内容被来自内容url的元数据所取代
- Swift:切换具有多个模式的案例不能绑定到variables
- 如何实例化和加载一个视图控制器,然后继续使用swift
- App crush:由于未捕获的exception“NSInternalInconsistencyException”而终止应用程序,原因是:“无效的更新:节0中的行数无效