有关如何将此数据从我的iOS AppDelegate.m
传递到我的WatchKit InterfaceController.m
的任何想法?< / p>
我在iOS Parse
AppDelegate.m
查询
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
NSString * request = [userInfo objectForKey:@"requestString"];
if ([request isEqualToString:@"executeMethodA"]) {
// GMT Date from Phone
NSDate *gmtNow = [NSDate date];
NSLog(@"GMT Now: %@", gmtNow);
// Query Parse
PFQuery *query = [PFQuery queryWithClassName:@"na"];
[query whereKey:@"dateGame" greaterThanOrEqualTo:gmtNow];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSMutableArray *localMatchup = [@[] mutableCopy];
for (PFObject *object in objects) {
// Add objects to local Arrays
[localMatchup addObject:[object objectForKey:@"matchup"]];
// App Group
NSString *container = @"group.com.me.off";
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:container];
// Matchup
[defaults setObject:localMatchup forKey:@"KeyMatchup"];
NSArray *savedMatchup = [defaults objectForKey:@"KeyMatchup"];
NSLog(@"Default Matchup: %@", savedMatchup);
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"dispatch");
});
reply(@{@"localMatchup": localMatchup});
}
else {
reply(@{@"error": error.description});
}
}];
}
}
很高兴发布任何额外的代码只是问,谢谢!
答案 0 :(得分:2)
reply
方法中有一个handleWatchKitExtensionRequest
块,当您完成查询时,在dict中使用您的数据运行它。
reply(@{@"localMatchup": localMatchup});
答案 1 :(得分:1)
我认为你可以调用handleWatchKitExtensionRequest方法