1

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;
}
GoodSp33d
  • 6,252
  • 4
  • 35
  • 67
simbesi.com
  • 1,539
  • 3
  • 17
  • 27

2 Answers2

2

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.

Schemetrical
  • 5,506
  • 2
  • 26
  • 43
  • If i follow any sample application i am getting data from my iPhone app app delegate class. Even if i put break point also it's not going there. @Schemetrical – simbesi.com Apr 16 '15 at 08:56
  • 1
    @RajuIstalla I know, thats why you need to attach to process to get the breakpoint to trip. If the application isn't returning anything, then there's a problem with your code on your phone (which it will not tell you unless you attach quick enough) – Schemetrical Apr 16 '15 at 14:01
0

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.

bgilham
  • 5,909
  • 1
  • 24
  • 39