मेरे पास एक ऐसा एप्लिकेशन है जो पृष्ठभूमि में ऑडियो चलाता है। मैं एक बग को ठीक करने की कोशिश कर रहा हूं जहां होम स्क्रीन (ऑडियो) पर ऑडियो नियंत्रण (प्ले/पॉज़) है, आईओएस 8.0+ पर काम न करें लेकिन आईओएस 7.0 पर ठीक काम करें। मैं यह पता लगाने की कोशिश कर रहा हूं कि समस्या क्या है और खाली हो रही है। किसी भी विचार की बहुत प्रशंसा की जाएगी। यहां मेरे पास जगह है।रिमोट कंट्रोल रिसीवइडथथेंट आईओएस 7.0 डिवाइस पर कॉल किया गया लेकिन आईओएस 8.0
प्रोजेक्ट सेटिंग्स में: मैंने यह सुनिश्चित किया है कि UIBackgroundModes
audio
पर सेट है।
AppDelegate.h में: मैं AVAudioSession* session;
के लिए एक सदस्य के रूप में अच्छी तरह से AVPlayer *audioPlayer;
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]);
}
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;
}
आप आप कैसे यह काम कर दिया पर कुछ प्रासंगिक कोड पोस्ट कर सकते हैं? 'UIWindow' के उप-वर्गीकरण को आपने कैसे और कहाँ किया था? – NorthBlast
समस्या गायब थी [खिड़की बनाने के लिए और दृश्यमान] कॉल। UIWindow कक्षा subclassing के साथ कुछ भी नहीं करने के लिए। – Caleb