从SiriKit的INExtension启动应用程序 [英] Launch app from INExtension in SiriKit

查看:167
本文介绍了从SiriKit的INExtension启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用SiriKit开始锻炼。开始锻炼需要从应用扩展程序中打开主应用程序。

I want to use SiriKit to start a workout. Starting the workout requires opening the main app from the app extension.

Apple为 INStartWorkoutIntentHandling 处理程序提供的样板是

The boilerplate that Apple provides for the INStartWorkoutIntentHandling handler is

func handle(startWorkout startWorkoutIntent: INStartWorkoutIntent, completion: (INStartWorkoutIntentResponse) -> Void) {
    let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent))
    let response = INStartWorkoutIntentResponse(code: .success, userActivity: userActivity)
    completion(response)
}

如何从这里打开自己的应用程序?类似 myapp:// workout?action = start& name = pushups 这个答案似乎不相关,因为我没有带 extensionContext的 UIViewController 此扩展类型的属性。

How can I open my own app from here? Something like myapp://workout?action=start&name=pushups This answer doesn't seem relevant, as I don't have a UIViewController with a extensionContext property for this extension type.

最后一个相关位:对于其他操作(暂停,结束)我不想打开主应用程序,而是打开只需暂停在主应用程序中运行的锻炼。我可以使用类似的自定义URL来暂停它,但这会打开应用程序,这是一个额外的不必要的步骤。有什么好方法告诉主应用程序在不打开应用程序的情况下从INExtension中采取特定操作?

Last related bit: For the other actions (pause, end) I’d prefer to not open the main app, but to simply pause the workout which is running in the main app. I could use a similar custom URL to pause it, but that would open up the app which is an extra unnecessary step. Any good way to tell the main app to take a specific action from the INExtension without opening the app?

推荐答案

对于后代:转向这是Xcode 8测试版之间的这个功能的分阶段,它已在Xcode 8 beta 3中得到解决。他们将 .continueInApp 代码添加到此版本中的INStartWorkoutIntentResponseCode ,但在Xcode 8 beta 2中没有。此状态代码允许直接传递NSUserActivity(无需使用URL方案)。

For posterity: turns out this was a phase-in of this functionality between Xcode 8 betas, it's been resolved in Xcode 8 beta 3. They added the .continueInApp code to INStartWorkoutIntentResponseCode in this version , but it wasn't there in Xcode 8 beta 2. This status code allows for the direct passing of NSUserActivity (no need to use a URL scheme).

这篇关于从SiriKit的INExtension启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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