Tag: ios9.3

KVO在iOS 9.3中破解

这可能是iOS 9.3(发行版)中的一个可怕的错误。 当添加一个观察者到[NSUserDefaults standardUserDefaults]我已经注意到响应方法-observeValueForKeyPath:ofObject:change:context:被多次调用。 在下面的简单示例中,每次按下一次UIButton,observeValueForKeyPath就会触发两次。 在更复杂的例子中,它会激发更多次。 它只出现在iOS 9.3(在SIM卡和设备上)。 这显然会对应用程序造成严重破坏。 任何人都经历了相同的? // ViewController.m (barebones, single view app) – (void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad"); [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"SomeKey" options:NSKeyValueObservingOptionNew context:NULL]; } – (IBAction)buttonPressed:(id)sender { NSLog(@"buttonPressed"); [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"SomeKey"]; } – (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { NSLog(@"observeValueForKeyPath: %@", keyPath); }

为什么AVPlayer在后台不能继续播放下一首歌?

我一直使用AVPlayer从远程来源播放音乐。 我得到的URL,使用一个创build一个AVPlayerItem,然后我与AVPlayer的实例关联。 我将一个观察者添加到与播放器关联的项目中,以观察项目何时完成播放( AVPlayerItemDidPlayToEndTimeNotification )。 当观察者在项目结束时通知我时,然后创build一个新的AVPlayerItem并重新执行。 这在iOS 9.2的前台和后台运行良好。 问题:由于我已经更新到iOS 9.3,这在后台不起作用。 这是相关的代码: var portionToBurffer = Double() var player = AVPlayer() func prepareAudioPlayer(songNSURL: NSURL, portionOfSongToBuffer: Double){ self.portionToBuffer = portionOfSongToBuffer //create AVPlayerItem let createdItem = AVPlayerItem(URL: songNSURL) //Associate createdItem with AVPlayer player = AVPlayer(playerItem: createdItem) //Add item end observer NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerItemDidReachEnd:", name: AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem) //Use KVO […]

调用openURL后,iOS 9.3冻结

在iOS 9.3上调用openURL后,我的应用程序冻结了13E233&13E234。 我尝试使用dispatch_after但是没有解决问题。 这是代码,没什么特别的。 + (void)someMethod:(UIView *)senderView { [Utility showLoadingHUDWithText:nil inView:senderView]; [[SomeClient sharedClient] someNetworkAPI:^(id result) { [Utility hideAllHUDsForView:senderView]; NSDictionary *dict = (NSDictionary *)result; NSString *someString = dict[@"someKey"]; NSURL *url = [NSURL URLWithString:someString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } } fail:^(NSError *error) { [Utility hideAllHUDsForView:senderView]; [Utility showMessageHUD:error.localizedDescription]; }]; } 这似乎是一个iOS的错误,也影响了许多其他的应用程序。