我目前有問題。 我想要的行爲:如果我打開我的WatchKit應用程序,我稱之爲「openParentApplication」。我收到我想要的數據。 但是,如果我在真實設備上測試過,它不起作用,因爲我在iPhone中打開了父應用程序。 但是當我在模擬器中測試時,它無需打開父應用程序。WatchKit openParentApplication:回覆
我的Xcode版本是6.3.2和iOS 8.3。
可能是什麼問題?
InterfaceController.m
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
NSDictionary *userInfo = @{@"request":@"refreshData"};
[WKInterfaceController openParentApplication:userInfo reply:^(NSDictionary *replyInfo, NSError *error)
{
entries = replyInfo;
NSLog(@"Reply: %@",replyInfo);
[self reloadTable];
[self.city setText:[entries valueForKey:@"city"][0] ];
}];
}
AppDelegate.m
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
NSString *refresh = [userInfo valueForKey:@"request"];
if([refresh isEqualToString:@"refreshData"])
{
NSString *city = [[NSUserDefaults standardUserDefaults] stringForKey:@"City"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:[NSString stringWithFormat:@"http://blackdriver.adappter.de/api/retrieve.php?city=%@",[city stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
{
reply(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];
}
}
編輯 - 正確答案: 看到評論
看到我的問題。 [鏈接](http://stackoverflow.com/questions/30703590/openparentapplication-only-works-when-the-app-is-running-in-the-foreground) –
這就是它的夥計!謝謝 :)! – TdoubleG