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);
}
我得到的错误是:
错误:错误域=com.apple.watchkit.errors 代码=2iPhone 应用程序中的 UIApplicationDelegate 从未在-[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]"UserInfo=0x7f8603227730 {NSLocalizedDescription=iPhone 应用程序中的 UIApplicationDelegate 从未在-[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}
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:]}
推荐答案
你需要调用reply block,即使你返回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);
}
参见 Apple 文档 了解更多信息.您还可以返回 NSDictionary reply(myNSDictionary);
包含返回到 Watchkit 扩展有用的任何信息,尽管字典只能包含可以序列化到属性列表文件的信息,所以例如,您可以传递字符串,但不能只传递包含对自定义类实例的引用的字典,而不先将它们打包为 NSData.
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屋!