ios – iPhone应用程序中的UIApplicationDelegate从未调用回复

前端之家收集整理的这篇文章主要介绍了ios – iPhone应用程序中的UIApplicationDelegate从未调用回复前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用以下代码从手表模拟器启动我的iPhone应用程序:

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: 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:]}

解决方法

您需要调用回复块,即使您返回零.以下将解决您的错误
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
NSLog(@"appdelegate handleWatchKitExtensionRequest");
NSLog(@"NSDictionary: %@",replyInfo);
reply(nil);
}

详见the Apple documentation.你也可以返回一个NSDictionary回复(myNSDictionary);无论什么信息,返回到您的Watchkit扩展将是有用的,虽然字典只能包含可以序列化属性列表文件的信息,所以例如你可以传递字符串,但你不能只传递包含引用的字典您的自定义类的实例,而不是首先将其打包成NSData.

原文链接:https://www.f2er.com/iOS/336837.html

猜你在找的iOS相关文章