我的應用程序要求用戶使用用戶名和密碼登錄。在手機上,這很好,但我想向蘋果手錶添加一些應用程序功能。是否可以將iPhone中的字符串(用戶名和密碼)傳遞給手錶登錄。 或者是否有更好的方法來執行此操作?在Apple Watch上登錄Parse.com
謝謝
我的應用程序要求用戶使用用戶名和密碼登錄。在手機上,這很好,但我想向蘋果手錶添加一些應用程序功能。是否可以將iPhone中的字符串(用戶名和密碼)傳遞給手錶登錄。 或者是否有更好的方法來執行此操作?在Apple Watch上登錄Parse.com
謝謝
我不明白你爲什麼會想從iPhone應用程序通過用戶名/密碼到WatchKit擴展自解析登錄代碼應該在iPhone上的側運行。
但是,要回答你的問題 - 是的,這是可能的。
某處WatchKit擴展你要給這樣的事情:(SWIFT)
WKInterfaceController.openParentApplication(["request": "user/pass"], reply: {
(reply, error) -> Void in
if reply != nil {
if let credential = reply["credential"] as? [String: String] {
let username = credential["username"]
let password = credential["password"]
}
}
})
在iPhone應用程序的AppDelegate中,覆蓋application:handleWatchKitExtensionRequest:reply:
和做這樣的事情:(Objective-C的)
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {
[self beginBackgroundTask];
if (userInfo != nil && userInfo[@"request"] != nil) {
NSString *request = userInfo[@"request"];
if ([request isEqualToString:@"user/pass"]) {
reply(@{@"username":USERNAME, @"password":PASSWORD});
}
}
[self endBackgroundTask];
}
你會如何建議從Watch端登錄Parse,而不是在你演示的時候傳遞用戶名和密碼? – user717452 2015-03-24 14:49:41
如果你已經在使用你的手機,爲什麼不直接在那裏登錄?兩個額外的步驟似乎是違背簡單的蘋果基礎。 – soulshined 2015-03-09 08:32:31