打开包含今日扩展程序的应用程序时崩溃 [英] Crash when open containing app from today extension

查看:183
本文介绍了打开包含今日扩展程序的应用程序时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了今天的扩展程序,并添加了一个按钮以打开包含应用程序的文件.内部扩展视图控制器:

I created today extension and add a button to open containing app. Inside extension view controller:

@IBAction func pressed() {
    extensionContext?.openURL(NSURL(string:"myApp://")!, completionHandler: nil)
}

因此,我还将URL方案添加到包含应用程序的plist中:

So, I also add URL Scheme to containing app plist:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>myApp</string>
        </array>
    </dict>
</array>

窗口小部件工作正常,但是当我尝试按窗口小部件时,我的应用程序在包含应用程序AppDelegate.swift的内部崩溃.无法达到application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?)内部的断点. 回溯:

Widget works fine, but when I try to press widget my app crashes inside containing app AppDelegate.swift. Breakpoint inside application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) can't be reached. Backtrace:

* thread #1: tid = 0x27fb0, 0x00000001861bd698 CoreFoundation`CFStringCreateCopy + 36, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001861bd698 CoreFoundation`CFStringCreateCopy + 36
    frame #1: 0x00000001019f7954 libswiftFoundation.dylib`Foundation._convertNSStringToString (ObjectiveC.NSString) -> Swift.String + 152
    frame #2: 0x000000010030172c myApp`@objc myApp.AppDelegate.application (myApp.AppDelegate)(ObjectiveC.UIApplication, openURL : ObjectiveC.NSURL, sourceApplication : Swift.String, annotation : Swift.Optional<Swift.AnyObject>) -> Swift.Bool + 104 at AppDelegate.swift:0
    frame #3: 0x000000018ad172f0 UIKit`-[UIApplication _applicationOpenURL:payload:] + 216
    frame #4: 0x000000018ad1b4c8 UIKit`-[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:] + 2420
    frame #5: 0x000000018ad1f810 UIKit`-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:] + 2220
    frame #6: 0x000000018ad1ecec UIKit`__88-[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]_block_invoke + 140
    frame #7: 0x000000018ad1ec44 UIKit`-[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 380
    frame #8: 0x000000018ad12578 UIKit`-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 512
    frame #9: 0x000000018e54562c FrontBoardServices`__31-[FBSSerialQueue performAsync:]_block_invoke + 28
    frame #10: 0x000000018628ea28 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
    frame #11: 0x000000018628db30 CoreFoundation`__CFRunLoopDoBlocks + 312
    frame #12: 0x000000018628c154 CoreFoundation`__CFRunLoopRun + 1756
    frame #13: 0x00000001861b90a4 CoreFoundation`CFRunLoopRunSpecific + 396
    frame #14: 0x000000018f35b5a4 GraphicsServices`GSEventRunModal + 168
    frame #15: 0x000000018aaee3c0 UIKit`UIApplicationMain + 1488
  * frame #16: 0x0000000100307df4 myApp`top_level_code + 76 at AppDelegate.swift:15
    frame #17: 0x0000000100307f0c myApp`main + 48 at AppDelegate.swift:0
    frame #18: 0x000000019709aa08 libdyld.dylib`start + 4

如果我在Safari中打开myApp://,则应用不会崩溃也可以正确打开.

If I open myApp:// in Safari, app open correctly w/o crash.

推荐答案

我遇到了一个非常相似的问题.我已经用这个Swift代码实现了application:openURL:sourceApplication:annotation::

I ran into a very similar issue. I'd implemented application:openURL:sourceApplication:annotation: with this Swift code:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {

但是事实证明sourceApplication实际上应该是可选的:

But it turns out that sourceApplication should actually be optional:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {

不知道我怎么弄错了(我假设Xcode是自动完成的,但是现在看来好像做对了),但是为我改正了它.

No idea how I got that wrong (I'm assuming Xcode autocomplete, but it seems to be doing the right thing now), but changing that fixed it for me.

这篇关于打开包含今日扩展程序的应用程序时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆