以下が実機の情報
- iOS 10.1.1
- iPhone7
最初はApple Developer Programは無料版で実機転送しておりましたが、途中から年間契約に切り替えました。
シミュレーターによるデバッグ時はMPNowPlayingInfoCenterによる曲情報表示やMPRemoteCommandCenterによる再生制御ができていたのですが、実機に転送するとできません。(Apple提供のデフォルトの音楽再生アプリ「ミュージック」だけの制御ができる状態)
以下がコードです。
application didFinishLaunchingWithOptionsにて実行しています。
objective
1__weak MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; 2commandCenter.changePlaybackPositionCommand.enabled = false; 3[commandCenter.changePlaybackPositionCommand addTarget:self 4 action:@selector(changedThumbSlider:)]; 5 6commandCenter.playCommand.enabled = false; 7commandCenter.pauseCommand.enabled = false; 8commandCenter.nextTrackCommand.enabled = false; 9commandCenter.previousTrackCommand.enabled = false; 10[commandCenter.playCommand addTarget:self action:@selector(play:)]; 11[commandCenter.pauseCommand addTarget:self action:@selector(pause:)]; 12[commandCenter.nextTrackCommand addTarget:self action:@selector(next:)]; 13[commandCenter.previousTrackCommand addTarget:self action:@selector(prev:)]; 14 15NSError *error = nil; 16__weak AVAudioSession *session = nil; 17session = [AVAudioSession sharedInstance]; 18 19[session setCategory:AVAudioSessionCategoryPlayback 20 withOptions:AVAudioSessionCategoryOptionMixWithOthers | 21 AVAudioSessionCategoryOptionDuckOthers 22 error:&error]; 23if (error) { 24 [self showError:error title:@"AudioSessionカテゴリ設定エラー"]; 25 return; 26} 27 28[_logs addObject:@"+Session Activate"]; 29error = nil; 30[session setActive:true 31 error:&error]; 32if (error) { 33 [self showError:error title:@"AudioSessionアクティベートエラー"]; 34 return; 35}
以下は曲の再生開始時に実行しています。
objective
1 __strong NSMutableDictionary *songInfo = nil; 2 __strong Media *media = self.currentMedia; 3 4 // music information 5 songInfo = [[NSMutableDictionary alloc] init]; 6 Float64 duration = CMTimeGetSeconds(self.queuePlayer.currentItem.duration); 7 Float64 elapsed = CMTimeGetSeconds(self.queuePlayer.currentTime); 8 [songInfo setObject:media.title forKey:MPMediaItemPropertyTitle]; 9 [songInfo setObject:media.album forKey:MPMediaItemPropertyAlbumTitle]; 10 [songInfo setObject:media.author forKey:MPMediaItemPropertyArtist]; 11 [songInfo setObject:[NSNumber numberWithFloat:1.0f] 12 forKey:MPNowPlayingInfoPropertyPlaybackRate]; 13 [songInfo setObject:[NSNumber numberWithDouble:duration] 14 forKey:MPMediaItemPropertyPlaybackDuration]; 15 [songInfo setObject:[NSNumber numberWithDouble:elapsed] 16 forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; 17 18 MPMediaItemArtwork *artwork = nil; 19 __strong UIImage *thumbnailImage = media.thumbnailImage; 20 artwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:thumbnailImage.size 21 requestHandler:^UIImage * _Nonnull(CGSize size) { 22 return thumbnailImage; 23 }]; 24 [songInfo setObject:artwork forKey:MPMediaItemPropertyArtwork]; 25 26 // update 27 __weak MPNowPlayingInfoCenter *nowPlayingInforCenter = nil; 28 nowPlayingInforCenter = [MPNowPlayingInfoCenter defaultCenter]; 29 [nowPlayingInforCenter setNowPlayingInfo:nil]; 30 [nowPlayingInforCenter setNowPlayingInfo:songInfo]; 31 artwork = nil; 32 songInfo = nil;
Capabilitiesの設定は、
- Background Modes は ON
- Audio, AirPlay, and Picture in Pictureにチェック
- Background fetchにチェック
- Remote notificationsにチェック
の状態です。
同様の現象が発生して解決された方はいらっしゃいませんか?
あなたの回答
tips
プレビュー