iPhone应用程序中的UIApplicationDelegate从未调用过回复 [英] The UIApplicationDelegate in the iPhone App never called reply
问题描述
我正在尝试使用以下代码从手表模拟器启动我的iPhone应用程序:
I am trying to launch my iPhone app from watch simulator using the below code :
WKInterfaceController子类
[WKInterfaceController openParentApplication:[NSDictionary dictionaryWithObject:@"red" forKey:@"color"] reply:^(NSDictionary *replyInfo, NSError *error) {
NSLog(@"replyInfo %@",replyInfo);
NSLog(@"Error: %@",error);
}];
AppDelegate.m
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
NSLog(@"appdelegate handleWatchKitExtensionRequest");
NSLog(@"NSDictionary: %@",userInfo);
NSLog(@"replyInfo: %@",replyInfo);
}
我得到的错误是:
错误:Error Domain = com.apple.watchkit.errors代码= 2 iPhone应用程序中的UIApplicationDelegate从未在 -[UIApplicationDelegate应用程序:handleWatchKitExtensionRequest:回复:] UserInfo = 0x7f8603227730 {NSLocalizedDescription = The iPhone应用程序中的UIApplicationDelegate从未在 -[UIApplicationDelegate应用程序:handleWatchKitExtensionRequest:回复:]}
Error: Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" UserInfo=0x7f8603227730 {NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}
推荐答案
即使返回nil
,也需要调用回复块.以下将解决您的错误:
You need to call the reply block, even if you return nil
. The following will resolve your error:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
NSLog(@"appdelegate handleWatchKitExtensionRequest");
NSLog(@"NSDictionary: %@",userInfo);
NSLog(@"replyInfo: %@",replyInfo);
reply(nil);
}
See the Apple documentation for further information. You can also return an NSDictionary reply(myNSDictionary);
with whatever information it would be useful to return to your Watchkit extension, although the dictionary can only contain information that can be serializable to a property list file, so for instance you can pass strings but you can't just pass a dictionary containing references to instances of your custom classes without packaging them up as NSData first.
这篇关于iPhone应用程序中的UIApplicationDelegate从未调用过回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!