2016-03-28 66 views
5

在iOS 9.3上調用openURL後,我的應用程序凍結13E233 & 13E234。iOS 9.3在致電openURL後凍結

我試過使用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的漏洞,許多其他應用程序的影響,太。

+0

你能顯示你的代碼嗎? – Fonix

+0

請問您可以發佈整個功能代碼嗎? –

+0

@Fonix添加代碼 –

回答

7

這確實會導致在iOS 9.3上的主線程上調用死鎖(在iPhone 6和iPhone 6 Plus上測試)。

semaphore

回溯:

* thread #1: tid = 0x41840, 0x0000000180ac1014 libsystem_kernel.dylib`semaphore_wait_trap + 8, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP 
    * frame #0: 0x0000000180ac1014 libsystem_kernel.dylib`semaphore_wait_trap + 8 
    frame #1: 0x000000010023fa20 libdispatch.dylib`_dispatch_semaphore_wait_slow + 244 
    frame #2: 0x0000000180bda934 libxpc.dylib`xpc_connection_send_message_with_reply_sync + 204 
    frame #3: 0x000000018276a238 MobileCoreServices`_LSStartOpenOperation + 232 
    frame #4: 0x0000000182791efc MobileCoreServices`-[LSOpenOperation main] + 1160 
    frame #5: 0x0000000182771bc0 MobileCoreServices`-[LSApplicationWorkspace openURL:withOptions:error:] + 472 
    frame #6: 0x000000018633cdd8 UIKit`-[UIApplication _openURL:] + 356 
    frame #7: 0x0000000100096c04 MyApp`__29-[ViewController someMethod]_block_invoke(.block_descriptor=0x0000000125d37e20) + 216 at ViewController.m:57 
    frame #8: 0x000000010022da7c libdispatch.dylib`_dispatch_call_block_and_release + 24 
    frame #9: 0x000000010022da3c libdispatch.dylib`_dispatch_client_callout + 16 
    frame #10: 0x00000001002334e4 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 2096 
    frame #11: 0x0000000180ef8dd8 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 
    frame #12: 0x0000000180ef6c40 CoreFoundation`__CFRunLoopRun + 1628 
    frame #13: 0x0000000180e20d10 CoreFoundation`CFRunLoopRunSpecific + 384 
    frame #14: 0x0000000182708088 GraphicsServices`GSEventRunModal + 180 
    frame #15: 0x00000001860f5f70 UIKit`UIApplicationMain + 204 
    frame #16: 0x00000001000970d0 MyApp`main(argc=1, argv=0x000000016fd6fae8) + 124 at main.m:14 
    frame #17: 0x00000001809be8b8 libdyld.dylib`start + 4 

我發現,包裹在dispatch_async塊整個呼叫固定的問題:

dispatch_async(dispatch_get_main_queue(), ^{ 
    if ([[UIApplication sharedApplication] canOpenURL:url]) { 
     [[UIApplication sharedApplication] openURL:url]; 
    } 
}); 

我會提交一份雷達與蘋果和張貼在Open Radar

貌似這個固定的iOS 9.3.1:

修復導致的應用程序,以輕拍在Safari和其他應用程序的鏈接後停止響應的問題。

+0

我在iOS 9.3的iPhone6上發現了同樣的錯誤。其實我無法使用Safari(我無法打開鏈接:S),所有使用'openURL'的應用程序都將崩潰。一個例子:** Slack **。奇怪的是,我的同事有相同的配置(iPhone6與iOS9.3),但錯誤不會發生 –

+0

其實我在控制檯中收到此錯誤: ':獲取NanoAppRegistry工作區信息時出錯信息:錯誤域= NSCocoaErrorDomain代碼= 4099「名爲com.apple.nanoappregistry.workspace的服務連接失效。」 UserInfo = {NSDebugDescription =與名爲com.apple.nanoappregistry.workspace的服務連接失效}' –

+0

它應該用'iOS 9.3.1'版本解決 –

0

我在iPad Air 2/3上運行iOS 9.3.5時面臨同樣的問題,JAL的答案並沒有爲我解決問題。

下面的代碼就像魅力一樣。

fileprivate func letApplicationHandleUrl(_ url: URL) { 

    guard UIApplication.shared.canOpenURL(url) else { 

     return 
    } 

    if #available(iOS 10.0, *) { 

     UIApplication.shared.open(url, options: [:], completionHandler: nil) 

    } else { 

     DispatchQueue.global(qos: .userInteractive).async { 

      UIApplication.shared.openURL(url) 
     } 
    } 
}