simbesi.com
simbesi.com

Reputation: 1529

To openParentApplication not responding handleWatchKitExtensionRequest in Watchkit Extension

I am trying to implement apple watch extension. I need to call my iPhone application class methods to trigger the web request. I saw this method in apple documentation i am trying the same.But this method is not calling

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

any help on this is appreciated. https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html

Here is my code snippet:

#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;
}

Upvotes: 1

Views: 482

Answers (2)

bgilham
bgilham

Reputation: 5939

In your app delegate you are checking for an object using the key requestString, when it has been stored in the dictionary using the key theRequestString. Additionally, you need to return something other than nil.

Upvotes: 0

Schemetrical
Schemetrical

Reputation: 5536

You must reply something. reply(@{});

Also, the method is being called, I'm just not sure you know how to debug the app. You need to go to Debug>Attach To Process>Your App Name (not watchkit app name). You have to do this quick before the process finishes or else it will not trip your breakpoint.

Upvotes: 2

Related Questions