在iOS 13中未调用application(... continue userActivity ...)方法 [英] application(...continue userActivity...) method not called in ios 13

查看:1143
本文介绍了在iOS 13中未调用application(... continue userActivity ...)方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UniversalLink制作ios应用.

Hi I'm making ios app using UniversalLink.

通用链接可以正常工作,但不会调用回调方法.

Universal Link works fine, but callback method is not called.

我的AppDelegate.swift在下面.

My AppDelegate.swift is below.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }


    func application(_ application: UIApplication,
                     willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        return true
    }

    // this method not called!!
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        print("called")
        return true
    }
}

该方法在iOS 12模拟器中被调用.

The method is called in iOS 12 Simulator.

因此,该问题仅在iOS 13中出现.

So, the problem is occured only in iOS 13.

仅在iOS13中,此错误会在控制台中显示.

Only in iOS13 this error is printed in console.

无法结束BackgroundTask:不存在标识符为1(0x1)的后台任务,或者它可能已经结束.中断UIApplicationEndBackgroundTaskError()进行调试.

Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

所以,这可能是问题的原因.

So, this may be cause of the problem.

我真的很感谢别人的帮助

I'd really appreciate someone help

推荐答案

就我而言,我在Xcode 11上启动了一个全新的项目,该项目使用SceneDelegateAppDelegate

In my case, I started a brand new project on Xcode 11 which uses SceneDelegate as well as AppDelegate

像UniversalLinks(可能还有其他几个API)一样在SceneDelegate上使用此回调:

Looks like UniversalLinks (and probably several other APIs) use this callback on the SceneDelegate:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { }

代替AppDelegate上的此回调:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { }

一旦我在SceneDelegate上实现了这一功能,一切就会再次按预期工作.我还没有尝试过,但是我假设如果您针对的是iOS 12及更低版本,则可能需要实现这两种方法.

Once I implemented the one on SceneDelegate everything started working as expected again. I haven't tried it, but I'm assuming that if you are targeting iOS 12 and below, you might need to implement both methods.

希望这会有所帮助

这篇关于在iOS 13中未调用application(... continue userActivity ...)方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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