OpenParentApplication: answer: error with asynchronous network call in application

I am getting an error while using my Watchkit app. When I launch it, I ask the containing iOS application to get some data from the network. The problem is that I get a message that the containing application never calls "reply ()": o But, looking at my code, it should call it.

I tried debugging every step from openParentApplication to calling "reply ()", and it seems to work well = X

Here is my watchkit extension code

- (void)initDiaporamasWithSuccess:(void (^)())success andFailure:(void (^)(NSError*))failure { NSLog(@"Ask to load diapos"); __weak typeof(self) weakSelf = self; [WKInterfaceController openParentApplication:@{@"watchKit": @"watchKit.initDiapos"} reply:^(NSDictionary *replyInfo, NSError *error) { if (error) { NSLog(@"%@", error); if (failure) { failure(error); } return; } NSLog(@"got items : %@", replyInfo[@"diapos"]); weakSelf.diaporamas = replyInfo[@"diapos"]; [weakSelf setDiaporama:replyInfo[@"firstDiapo"] AtIndex:0]; if (success) { success(); } }]; 

}

The result should be an NSDictionary containing an NSArray with some basic diaporamas informational materials and an object (Diapo) containing complete information about the first diapore (for example, self.diaporamas [0])

And here is the code in the containing AppDelegate application:

 - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply { // Maybe we could handle multiple watchKit extension calls that way ? // Something like a key-value 'protocol' to run the right block of code NSString *watchKitCall = userInfo[@"watchKit"]; NSLog(@"watchKit handled"); if ([watchKitCall isEqualToString:@"watchKit.initDiapos"]) { [AppDelegate watchInitialObjects:^(NSDictionary *info) { NSLog(@"Managed to get initial infos"); reply(info); } failure:^(NSError *error) { NSLog(@"Fail : %@", error); reply(@{@"error": error}); }]; } 

}

 + (void) watchInitialObjects:(void (^)(NSDictionary *info))success failure:(void (^)(NSError *error))failure { NSDictionary *parameters = @{@"site" : @(14), @"limit" : @(10)}; [AppDelegate requestDiapoListWithParams:parameters success:^(NSArray *items) { if ([items count] == 0) { NSError *error = [NSError errorWithDomain:@"com.domain.app" code:404 userInfo:nil]; failure(error); return; } Diapo *firstDiapo = [items firstObject]; [AppDelegate requestDiapoDetailWithDiapo:firstDiapo success:^(Diapo *diapo) { if (!diapo) { NSError *error = [NSError errorWithDomain:@"com.domain.app" code:404 userInfo:nil]; failure(error); return; } NSDictionary *result = @{ @"firstDiapo" : diapo, @"diapos" : items }; success(result); } failure:^(NSError *error) { failure(error); }]; } failure:^(NSError *error) { failure(error); }]; 

}

In watchKitHandler, I call watchInitialObjects to get an array of diaparats and the first diapore information. In watchInitialObjects, I make the first network call to get the array, and on success, I make another network call to get the diaspora information.

To make calls and map JSON to objects, I use RESTKit

I really don't understand what could be the error = x

UPDATE

I forgot to write the error I get, here it is:

Domain error = com.apple.watchkit.errors Code = 2 "UIApplicationDelegate in the iPhone application never triggered a response () in - [UIApplicationDelegate application: handleWatchKitExtensionRequest: reply:]" UserInfo = 0x7fcb53e12830 {NSLocalizedDescription = UIApplication Application never () in [UIApplicationDelegate application: handleWatchKitExtensionRequest: reply:]}

And I kept trying to understand why I got this error, and I think I found: It seems that there is a (very small) timeout to do the work in the containing application. But I matched the JSON data that I received directly in the containing application, and then send these custom objects in response (). But when I removed the display part, it worked well!

So ... why do I think it was a problem = X Can anyone approve of my thoughts or correct me?

+7
ios objective-c networking watchkit restkit
source share
1 answer

After hours of searching and testing different codes, I finally found my problem ... and this is obvious when we read the Apple documentation about the application: handleWatchKitExtensionRequest: reply: 'seriously ...

here is the answer: (this is in the documentation)

The contents of the dictionary must be serialized in the property list file.

This means that objects can be ONLY dictionaries, arrays, strings, numbers (integer and float), dates, binary data, or logical values

... I feel dumb> <

+9
source share

All Articles