我在我们的应用程序中实现了CallKit . 我们的应用程序制作调用显示在本机电话应用程序的最新列表中 .
在最近列表中点击我们的应用程序条目时,我们的应用程序已启动 . 有没有办法找出用于启动我们的应用程序的数字(/条目)? (openURL或其他)
您需要在AppDelegate上实现 application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool . 对于此特定操作, userActivity 将具有 interaction 属性,其 intent 属性是 INStartAudioCallIntent 的实例(如果您的应用执行视频,则为 INStartVideoCallIntent ) .
application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool
userActivity
interaction
intent
INStartAudioCallIntent
INStartVideoCallIntent
intent对象上有一个 INPerson 联系对象数组,可用于确定有关所拨内容的信息 .
INPerson
如果您的应用程序没有't load any contacts into the system, your calls are one-to-one (as opposed to group) and you just want access to the 2432969 , you'可能会在 intent.contacts?.first?.personHandle?.value 找到您想要的内容 .
intent.contacts?.first?.personHandle?.value
另请注意,您需要链接并导入 Intents 框架 .
Intents
Update
之前的答案只有一半是正确的 . 有两种获取此信息的方法,两者都应该实现 .
当点击最近的项目(或选择联系人)并且您的应用程序已在运行时,将调用上面的continueUserActivity变体 .
但是,如果您的应用当前未运行,则会启动它并且不会调用 continueUserActivity . 相反,系统将使用 UIApplicationLaunchOptionsKey.userActivityDictionary 调用AppDelegate的 didFinishLaunchingWithOptions ,可以使用如下:
continueUserActivity
UIApplicationLaunchOptionsKey.userActivityDictionary
didFinishLaunchingWithOptions
if let activityOptions = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] as? [String: AnyObject], let activity = activityOptions["UIApplicationLaunchOptionsUserActivityKey"] as? NSUserActivity { self.launchWithActivity(activity) }
拥有 NSUserActivity 实例后,行为与 continueUserActivity 中的行为相同
NSUserActivity
Update Again
根据以下评论中的@vivek takrani,无论应用程序以前是否打开,似乎都可以随时调用 continueUserActivity . 如果你打算支持它,我会在iOS 10的早期版本上测试这个,因为我不相信这个答案写的时候就是这种情况 .
1 回答
您需要在AppDelegate上实现
application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool
. 对于此特定操作,userActivity
将具有interaction
属性,其intent
属性是INStartAudioCallIntent
的实例(如果您的应用执行视频,则为INStartVideoCallIntent
) .intent对象上有一个
INPerson
联系对象数组,可用于确定有关所拨内容的信息 .如果您的应用程序没有't load any contacts into the system, your calls are one-to-one (as opposed to group) and you just want access to the 2432969 , you'可能会在
intent.contacts?.first?.personHandle?.value
找到您想要的内容 .另请注意,您需要链接并导入
Intents
框架 .Update
之前的答案只有一半是正确的 . 有两种获取此信息的方法,两者都应该实现 .
当点击最近的项目(或选择联系人)并且您的应用程序已在运行时,将调用上面的continueUserActivity变体 .
但是,如果您的应用当前未运行,则会启动它并且不会调用
continueUserActivity
. 相反,系统将使用UIApplicationLaunchOptionsKey.userActivityDictionary
调用AppDelegate的didFinishLaunchingWithOptions
,可以使用如下:拥有
NSUserActivity
实例后,行为与continueUserActivity
中的行为相同Update Again
根据以下评论中的@vivek takrani,无论应用程序以前是否打开,似乎都可以随时调用
continueUserActivity
. 如果你打算支持它,我会在iOS 10的早期版本上测试这个,因为我不相信这个答案写的时候就是这种情况 .