Mam aplikację, która odtwarza dźwięk w tle. Próbuję naprawić błąd, w którym elementy sterowania dźwiękiem (odtwarzanie/pauza) na ekranie głównym (itp.) NIE DZIAŁAJĄ w systemie iOS 8.0+, ale działają w trybie FINE na iOS 7.0. Przekopuję się, próbując dojść do tego, o czym jest problem, i doszedłem do pustki. Wszelkie pomysły będą mile widziane. Oto, co mam na miejscu.remoteControlReceivedWithEvent wywołane na urządzeniu z iOS 7.0, ale nie iOS 8.0
W Ustawieniach projektu: Upewniłem się, że UIBackgroundModes
jest ustawione na audio
.
W AppDelegate.h: Mam członka na AVAudioSession* session;
jak również AVPlayer *audioPlayer;
W AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.session = [AVAudioSession sharedInstance];
NSError* error = NULL;
[self.session setCategory:AVAudioSessionCategoryPlayback error:&error];
[self.session setActive:YES error:&error];
if (error) {
NSLog(@"AVAudioSession error: %@", [error localizedDescription]);
}
W AudioPlayerViewController.m
- (void)viewDidLoad {
//Get the Audio
NSURL *url = [NSURL URLWithString:self.audioUrl];
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
//Setup the player
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
appDelegate.audioPlayer = [AVPlayer playerWithPlayerItem:self.playerItem];
//Setup the "Now Playing"
NSMutableDictionary *mediaInfo = [[NSMutableDictionary alloc]init];
[mediaInfo setObject:self.title forKey:MPMediaItemPropertyTitle];
[mediaInfo setObject:self.artist forKey:MPMediaItemPropertyArtist];
[mediaInfo setObject:self.album forKey:MPMediaItemPropertyAlbumTitle];
[mediaInfo setObject:[NSNumber numberWithDouble:duration ] forKey:MPMediaItemPropertyPlaybackDuration];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
}
// Process remote control events
- (void) remoteControlReceivedWithEvent:(UIEvent *)event {
NSLog(@"AudioPlayerViewController ... remoteControlReceivedWithEvent top ....subtype: %d", event.subtype);
if (event.type == UIEventTypeRemoteControl) {
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[self togglePlayPause];
break;
case UIEventSubtypeRemoteControlPause:
[self doPause];
break;
case UIEventSubtypeRemoteControlStop:
[self doPause];
break;
case UIEventSubtypeRemoteControlPlay:
[self doPlay];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
[self nextOrPrevTrack];
break;
case UIEventSubtypeRemoteControlNextTrack:
[self nextOrPrevTrack];
break;
default:
break;
}
}
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (BOOL) canBecomeFirstResponder {
return YES;
}
można zakładać jakiś odpowiedni kod, w jaki zrobiłeś to działa? Podobnie jak i gdzie zrobiłeś podklasę 'UIWindow'? – NorthBlast
Problem polegał na braku połączenia [window makeKeyAndVisible]. Nie ma to nic wspólnego z podklasowaniem klasy UIWindow. – Caleb