我想使用 SiriKit 开始锻炼。开始锻炼需要从应用程序扩展打开主应用程序。
Apple 提供的样板文件INStartWorkoutIntentHandling
处理程序是
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
这个答案 https://stackoverflow.com/questions/24356314/openurl-from-app-extension似乎不相关,因为我没有UIViewController
with a extensionContext
此扩展类型的属性。
最后相关的一点:对于其他操作(暂停、结束),我不想打开主应用程序,而是简单地暂停在主应用程序中运行的锻炼。我可以使用类似的自定义 URL 来暂停它,但这会打开应用程序,这是一个额外不必要的步骤。有什么好方法可以告诉主应用程序在不打开应用程序的情况下从 INExtension 执行特定操作吗?
对我来说,我能够像这样启动应用程序:
let activity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
activity.webpageURL = URL(string: "https://mywebsite/...")
completion(MyIntentResponse(code: .continueInApp, userActivity: activity))
然后这将在 AppDelegate 中被调用
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
if let url = userActivity.webpageURL {
handleDeeplink(url)
}
}
return false
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)