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

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

WKInterfaceController子类

  1. [WKInterfaceController openParentApplication:[NSDictionary dictionaryWithObject:@"red" forKey:@"color"] reply:^(NSDictionary *replyInfo,NSError *error) {
  2. NSLog(@"replyInfo %@",replyInfo);
  3. NSLog(@"Error: %@",error);
  4. }];

AppDelegate.m

  1. - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
  2. {
  3. NSLog(@"appdelegate handleWatchKitExtensionRequest");
  4. NSLog(@"NSDictionary: %@",userInfo);
  5. NSLog(@"replyInfo: %@",replyInfo);
  6. }

我得到的错误是:

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

解决方法

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

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

猜你在找的iOS相关文章