2015-04-01 79 views
1

我想要显示用户在Apple Watch上收到的文本的简要摘要。然后,他们可以通过点击iWatch App中的按钮来阅读其iPhone上的文本。我不认为这是现在可能的,但如果是这样,请让我知道我需要做什么才能做到这一点。是否可以使用Apple Watch打开iPhone App?

回答

2

您可以在后台与

+ (BOOL)openParentApplication:(NSDictionary *)userInfo 
         reply:(void (^)(NSDictionary *replyInfo, 
             NSError *error))reply 

打开您的iOS应用iOS应用会得到

- (void)application:(UIApplication *)application 
handleWatchKitExtensionRequest:(NSDictionary *)userInfo 
       reply:(void (^)(NSDictionary *replyInfo))reply 

所以,如果您的iOS应用程序已经在运行,你可以使用这个信息提供给应用程序。但是,您不能让iOS应用程序在前台运行,必须由用户启动。您可以将文本的其余部分保存到共享设置中,并/或在后台将其传递到您的应用程序openParentApplication。然后,当用户打开你的iOS应用程序时,你可以向他们展示文本的其余部分。

0

不,不可以通过手表在iPhone上打开您的应用程序,但是您可以在后台打开您的应用程序。

假设您想要查看手表上的新闻,并且需要数据。你得到的是通过iPhone应用程序与数据:openParentApplication:handleWatchKitExtensionRequest:

如何做到这一点是在这个答案解释: How to send data from iphone to watchkit in swift

1

如果您需要在前台打开你的父应用程序,使用切换!

https://developer.apple.com/handoff/

某处对于共享:

static let sharedUserActivityType = "com.yourcompany.yourapp.youraction" 
static let sharedIdentifierKey = "identifier" 

您关注:

updateUserActivity(sharedUserActivityType, userInfo: [sharedIdentifierKey : 123456], webpageURL: nil) 

在您的iPhone应用程序中的代表:

func application(application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool { 
    if (userActivityType == sharedUserActivityType) { 
     return true 
    } 
    return false 
} 

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool { 
    if (userActivity.activityType == sharedUserActivityType) { 
     if let userInfo = userActivity.userInfo as? [String : AnyObject] { 
      if let identifier = userInfo[sharedIdentifierKey] as? Int { 
       //Do something 
       let alert = UIAlertView(title: "Handoff", message: "Handoff has been triggered for identifier \(identifier)" , delegate: nil, cancelButtonTitle: "Thanks for the info!") 
       alert.show() 
       return true 
      } 
     } 
    } 
    return false 
} 

最后(这一步是很重要!!!):在你的Info.plist(S)

enter image description here

+0

Apple关注不有Handoff。它是iOS和OS X功能。 – 2015-04-18 14:07:42

+0

我不能谈论它,但请相信我:您可以从手表切换到其他Apple设备。 – stk 2015-04-18 18:05:37

相关问题