Reputation: 341
Okay so I'm making this Apple Watch app and in my Watch App, I have a button. When you touch the button, it does this:
[WKInterfaceController openParentApplication:[NSDictionary dictionary] reply:^(NSDictionary *replyInfo, NSError *error) {
if(error) {
NSLog(@"%@",error);
}
}];
And in my App Delegate file I do this:
-(void) application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {
//Code that is not importent and is confidential
reply([NSDictionary dictionary]);
}
Yet I get this error when I press the button:
Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" UserInfo=0x7fd2b9c35ae0 {NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}
I'm calling reply()
as shown above but it doesn't see that! Also, it's ignoring the other code I have in there!
Can anybody explain why this is happening?
Upvotes: 2
Views: 3285
Reputation: 671
You may have trouble if your dictionary includes custom classes. Try to send simple strings first and see if that makes a difference.
Check that your "important and confidential" code does not raise exception, or finish without calling a reply (with a error payload, for example).
Your "important and confidential" code must be really quick. If that is not the case, you have to use a background task (see here for examples).
Finally, consider using a background task if your code takes time, does network access. If you use asynchronous network tasks (recommended), reply when you receive the answer, and finish the background task at that time.
Last but not least, the first call to parentApplication fails on some iOS versions : Inconsistent behavior of openParentApplication in my WatchKit App. This solved the last issue for me!
Hope that helps ;-)
Upvotes: 0
Reputation: 7307
From the documentation:
replyInfo: A dictionary containing data to return to the WatchKit app. The contents of the dictionary must be serializable to a property list file. The contents of this dictionary are at your discretion and you may specify nil.
If you don't send a valid dictionary, you will not get a reply.
Upvotes: 3
Reputation: 531
The error "Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" generally means that your app's handleWatchKitExtensionRequest had an error and/or did not call reply() or call it correctly.
The documentation is here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/application:handleWatchKitExtensionRequest:reply:
Here is a bit of simple sample code using a NSDictionary response.
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{
NSLog(@"containing app received message from watch");
NSDictionary *response = @{@"response" : @"MyResponse"};
reply(response);
}
Upvotes: 0
Reputation: 5939
You need to perform all work in handleWatchKitExtensionRequest
in a background task. You can find the documentation here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
This blog post may also prove helpful: http://www.fiveminutewatchkit.com/blog/2015/3/11/one-weird-trick-to-fix-openparentapplicationreply
Upvotes: 1