简体   繁体   English

从Swift 4中的Today扩展打开时,包含应用程序崩溃

[英]Containing App crashes when opened from Today extension in swift 4

i have a swift app for which i have a today extension,it has a button which opens the containing app. 我有一个快速应用程序,我有一个今天的扩展程序,它有一个按钮可以打开包含的应用程序。

the button opens the app perfectly when the app is in the recent list but crashes when the app is moved from the recent list. 当应用程序位于最近列表中时,该按钮可以完美地打开该应用程序,但是当该应用程序从最近列表中移出时,该按钮会崩溃。

there's no crashlogs too 也没有崩溃日志

this is my code on app delegate : 这是我在应用程序委托上的代码:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    var mainViewController : MainViewController!
    mainViewController = UIApplication.shared.keyWindow?.rootViewController?.childViewControllers[1].childViewControllers[0] as! MainViewController

    if url.scheme == "open"
    {
        switch url.host
        {
        case "1"?:
            mainViewController.isTaxi = true
            break
        case "2"?:
           mainViewController.isPfp = true
            break
        case "3"?:
           mainViewController.isDarbi = true
            break
        default:
            break
        }
    }
    return true
}

this is how i open in main VC : 这就是我在主VC中打开的方式:

var isTaxi : Bool? {
    didSet{
        if UserDefaults.getUser() != nil {
            self.taxiRegViewController.show()
        } else {
            self.taxiNotRegViewController.show()
        }
    }
}

this is where i fire tap event in extension : 这是我在扩展中触发点击事件的地方:

@IBAction func bookTaxiTapped(_ sender: UIButton) {
    if let url = URL(string: "open://\(sender.tag)")
    {
        self.extensionContext?.open(url, completionHandler: nil)
    }
}

I solved my problem,by modifying the app delegate's method like this : 通过修改应用程序委托的方法,我解决了我的问题:

Actual Problem was : we had SWRevealViewController which has to be initiated before calling other view controller's 实际问题是:我们有SWRevealViewController,必须在调用其他视图控制器的SWRevealViewController之前将其启动

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    var mainViewController : MainViewController!
    self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)

    let viewController = storyBoard.instantiateViewController(withIdentifier: "swRevealController") as! SWRevealViewController
    mainViewController = storyBoard.instantiateViewController(withIdentifier: "mainView") as! MainViewController
    self.window?.rootViewController = viewController
    self.window?.makeKeyAndVisible()

    viewController.setFront(mainViewController, animated: true)


    if url.scheme == "open"
    {
        switch url.host
        {
        case "1"?:
            mainViewController.isTaxi = true
            break
        case "2"?:
           mainViewController.isPfp = true
            break
        case "3"?:
           mainViewController.isDarbi = true
            break
        default:
            break
        }
    }
    return true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从今天扩展名打开时,iOS应用程序崩溃 - iOS app crash when opened from today extension 打开包含今日扩展的应用程序时崩溃 - Crash when open containing app from today extension 当主应用程序未打开时,Swift 如何从今天的扩展中打开特定的视图控制器 - Swift how to open specific viewcontroller from today extension when main app is not open 如何将应用程序中的数据显示到 Today Extension Swift - How to show data from app to Today Extension Swift 如何从Swift的Today扩展中的父iPhone应用程序中调用方法? - How to call a method in the parent iPhone app from Today Extension in Swift? iOS Swift Today Extension:从容器应用程序导入类? - iOS Swift Today Extension: import class from container app? 从TestFlight打开应用时崩溃,否则可以正常工作 - App crashes when opened from TestFlight but works fine otherwise 直接从iPhone打开时,iOS App崩溃并关闭 - iOS App crashes and closes when opened directly from the iPhone 调试/运行iOS8 App Today Extension时,Xcode将多个包含应用程序安装到设备上 - Xcode installs multiple containing apps onto device when debugging/running iOS8 App Today Extension 今日应用扩展小部件点击以打开包含应用 - Today App Extension Widget Tap To Open Containing App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM