【发布时间】:2015-06-07 08:53:18
【问题描述】:
我目前有一个问题。 我想要的行为:如果我打开我的 WatchKit 应用程序,我会调用“openParentApplication”。我收到了我想要的数据。 但是如果我在真实设备上进行测试,因为我在 iPhone 中打开父应用程序,所以它不起作用。 但是当我在模拟器中进行测试时,它无需打开父应用程序即可工作。
我的 Xcode 版本是 6.3.2 和 iOS 8.3。
可能是什么问题?
接口控制器.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);
}];
}
}
编辑 - 正确答案: 在 cmets 中查看 mohammed alwaili 的链接
【问题讨论】:
-
看我的问题。 link
-
就是这样,伙计!谢谢:)!
标签: ios iphone xcode6 watchkit