繁体   English   中英

若要在Watchkit Extension中打开openParentApplication不响应handleWatchKitExtensionRequest

[英]To openParentApplication not responding handleWatchKitExtensionRequest in Watchkit Extension

我正在尝试实现Apple Watch扩展。 我需要调用我的iPhone应用程序类方法来触发Web请求。 我在苹果文档中看到了这种方法,但我没有尝试

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply

任何帮助对此表示赞赏。 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html

这是我的代码段:

#import "InterfaceController.h"

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];

    // Configure interface objects here.
    NSString *requestString = [NSString  stringWithFormat:@"callMyRequest"];
    NSDictionary *applicationData = [[NSDictionary alloc] initWithObjects:@[requestString] forKeys:@[@"theRequestString"]];

    [WKInterfaceController openParentApplication:applicationData reply:^(NSDictionary *replyInfo, NSError *error) {
        NSLog(@"\nReply info: %@\nError: %@",replyInfo, error);
    }];
}

#import "Appdelegate.h"
#import "MyController.h"

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^) (NSDictionary *replyInfo))reply {
    NSString * request = [userInfo objectForKey:@"requestString"];

    if ([request isEqualToString:@"callMyRequest"]) {
        // Do whatever you want to do when sent the message. For instance...
        MyController*  myController = [[MyController alloc] init];
        [myController callMyRequest];
    }

    reply nil;
}

你必须回信。 reply(@{});

另外,该方法正在被调用,我只是不确定您是否知道如何调试应用程序。 您需要转到“调试”>“附加到进程”>“您的应用程序名称”(而不是watchkit应用程序名称)。 您必须在完成该过程之前快速执行此操作,否则它将不会使您的断点跳闸。

在您的应用程序委托中,您正在使用键requestString检查对象,当该对象已通过键theRequestString存储在字典中时。 此外,您需要返回nil以外的其他值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM