CallKit查找用于从本机手机应用启动应用的号码 [英] CallKit find number used to start app from native phone app

查看:183
本文介绍了CallKit查找用于从本机手机应用启动应用的号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的应用程序中实现了CallKit。我们的应用程序制作调用显示在原生手机应用程序的最近列表中。

I've implemented CallKit in our app. Calls our app makes are displayed in the native phone app's recents list.

在最近列表中点击我们的应用程序条目时,我们的应用程序已启动。有没有办法找出用于启动我们的应用程序的数字(/条目)? (openURL或其他)

When tapping an entry for our app in the recents list, our app is started. Is there a way to find out which number(/entry) was used to start our app? (openURL or something)

推荐答案

您需要实现应用程序(应用程序:UIApplication,continueUserActivity userActivity :NSUserActivity,restorationHandler:([AnyObject]?) - > Void) - > AppDelegate上的Bool 。对于此特定操作, userActivity 将具有交互属性,其中 intent 属性是 INStartAudioCallIntent 的实例(或 INStartVideoCallIntent 如果你的应用是视频)。

You'll want to implement application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool on the AppDelegate. For this particular action, userActivity will have a interaction property, with an intent property that is an instance of INStartAudioCallIntent (or INStartVideoCallIntent if your app does video).

intent对象上有一个 INPerson 数组的联系对象,可用于确定有关所拨内容的信息。

The intent object has an array of INPerson contact objects on it, which can be used to determine information about what was dialed.

如果您的应用没有将任何联系人加载到系统中,您的呼叫是一对一的(而不是组),您只需要访问拨打的号码,你可能会在 intent.contacts找到你想要的东西?。first?.personH​​andle?.value

If your app doesn't load any contacts into the system, your calls are one-to-one (as opposed to group) and you just want access to the "dialed number", you'll probably find what you want at intent.contacts?.first?.personHandle?.value.

另请注意,您需要链接并导入 Intents 框架。

Also note that you'll need to link and import the Intents framework.

更新

之前的回答只有一半。有两种获取此信息的方法,两者都应该实现。

The previous answer was only half-right. There are two ways of getting this information, and both should be implemented.

当点击最近的项目(或选择了联系人)时,将调用上面的continueUserActivity变体),并且您的应用已在运行

The continueUserActivity variant above will be called when an item in recents is tapped (or a contact is selected), and your app is already running.

但是,如果您的应用当前未运行,则会启动并且 continueUserActivity 将不会被调用。相反,系统将使用 UIApplicationLaunchOptionsKey.userActivityDictionary 调用AppDelegate的 didFinishLaunchingWithOptions ,可以像以下一样使用:

However, if your app is not currently running, then it will be launched and continueUserActivity will not be called. Instead, the system will invoke your AppDelegate's didFinishLaunchingWithOptions with a UIApplicationLaunchOptionsKey.userActivityDictionary, which can be used like:

if let activityOptions = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] as? [String: AnyObject],
   let activity = activityOptions["UIApplicationLaunchOptionsUserActivityKey"] as? NSUserActivity {
  self.launchWithActivity(activity)
}

一旦你拥有了 NSUserActivity 实例,行为与中的行为相同> continueUserActivity

Once you have the NSUserActivity instance, the behavior is the same as it is in continueUserActivity

再次更新

在下面的评论中,每个@vivek takrani,似乎 continueUserActivity 。如果你打算支持它,我会在早期版本的iOS 10上测试它,因为我不相信这个答案是在写这个答案时的情况。

Per @vivek takrani in the comments below, it appears that continueUserActivity may be called at all times, whether the app was previously open or not. I would test this on earlier versions of iOS 10 if you intend to support it, as I don't believe this was the case at the time this answer was written.

这篇关于CallKit查找用于从本机手机应用启动应用的号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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