私のアプリでは、ユーザーがバックグラウンドでオーディオ再生を制御できるようにします。 .plistでbackGroundモードを設定していたのと同じようにbgで再生しました。しかし、コントロールボタンに触れても反応はありません。iOSのReceiveRemoteControlEventsを開始できません
私は私のプレーヤーが私にbeginReceivingRemoteControlEvents
このような
if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
[self becomeFirstResponder];
NSLog(@"Responds!");
}
を入れて、それがResponds!
を印刷します。しかし、問題があることですviewContollerで、その後AudioSession
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance]setActive:YES error:nil];
を設定
このメソッドは決して呼び出されません
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
NSLog(@"Where is my event?");
if(event.type == UIEventTypeRemoteControl)
{
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"Pause");
[self playWords:playButton];
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(@"Next");
[self next];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(@"Prev");
[self prev];
break;
}
}
私もそれがファーストレスポンダになるようにするUIApplication
上のカテゴリを書き込もうとしましたが、それは
@implementation UIApplication (RemoteEvents)
-(BOOL)canBecomeFirstResponder
{
return YES;
}
@end
は、なぜこれが発生する可能性が助けていないのですか?
SOLUTION は、ここで私は、それが正常に働いている私のプロジェクトで同じ仕事をしている私の問題Entering background on iOS4 to play audio
ありがとうございます、私が見る限り、それはちょうど同じです –
別のことは、シミュレータを使用してイベントを削除し、音楽をバックグラウンドでテストしている場合、シミュレータでテストすることができないことです。 –
私はデバイス上でテストする) –