Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handleWatchKitExtensionRequest is not called

Tags:

ios

watchkit

I am trying to launch the parent ios app from watchkit app. I'm using url scheme to launch the app.But it seems like

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

is nevered called. It seems like watch app does launch the app in backgound. But the parent app does not handle the watchkit request. I tried my approach in a new project and it works perfectly. Is there any thing I need to pay attention?

I've already tried to Debug>Attach to process>myapp and put a breakpoint inside handleWatchKitExtensionRequest method to confirm if it is called and it isn't called.

Here is the progress, I call openParentApplication when a button is clicked in watch app.

@IBAction func viewOniPhoneAction() {


    let userInfo: [NSObject : AnyObject] = [
        "userID" : user.userID
    ]


    WKInterfaceController.openParentApplication(userInfo, reply: { (userInfo : [NSObject : AnyObject]!, error : NSError!) -> Void in

    })

}

Here is my app delegeate

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
NSDictionary *replyDict = @{@"response": @"done"};
reply(replyDict);
}

I tried reply() in handleWatchKitExtensionRequest but I got this error in reply block from watch app

Error Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" UserInfo=0x60800026e0c0 {NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}
like image 548
cloudy45man Avatar asked May 21 '15 08:05

cloudy45man


1 Answers

I got it to work!!! Having the same issue....

Just increase the beginBackgroundTaskWithExpirationHandler time to a larger value if you still don't get the data!!! I used 2 secs previously but my network is too weak!!!

I call openParentApplication when a button is clicked in watch app:

[WKInterfaceController openParentApplication:loadDetailChatDataDictionary reply:^(NSDictionary *replyInfo, NSError *error) {

Here is my app delegate:

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

    __block UIBackgroundTaskIdentifier bogusWorkaroundTask;
    bogusWorkaroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:bogusWorkaroundTask];
    }];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // increase the time to a larger value if you still don't get the data!!! I used 2 secs previously but my network is too weak!!!
        [[UIApplication sharedApplication] endBackgroundTask:bogusWorkaroundTask];
    });
    // --------------------

    __block UIBackgroundTaskIdentifier realBackgroundTask;
    realBackgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        reply(nil);
        [[UIApplication sharedApplication] endBackgroundTask:realBackgroundTask];
    }];

    NSString *value = userInfo[@"key"];
    if ([value isEqualToString:@"loadRecentChatData"]) {
                 reply(@{@"recents":recents}); // Add your reply here
    }
like image 117
user1872384 Avatar answered Oct 31 '22 12:10

user1872384