`UIApplicationDelegate` 到 `WKInterfaceController` 数据传递
`UIApplicationDelegate` to `WKInterfaceController` data pass
关于如何将此数据从我的iOSAppDelegate.m
传递到我的WatchKit的任何想法InterfaceController.m
?
我 运行 在我的 iOS AppDelegate.m
中有一个 Parse
查询
- (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});
}
}];
}
}
很高兴post任何额外的代码只问,谢谢!
您的 handleWatchKitExtensionRequest
方法中有一个 reply
块,当您完成查询时,运行 它与您的数据一起存储在字典中。
reply(@{@"localMatchup": localMatchup});
我想你可以调用 handleWatchKitExtensionRequest 方法
关于如何将此数据从我的iOSAppDelegate.m
传递到我的WatchKit的任何想法InterfaceController.m
?
我 运行 在我的 iOS AppDelegate.m
Parse
查询
- (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});
}
}];
}
}
很高兴post任何额外的代码只问,谢谢!
您的 handleWatchKitExtensionRequest
方法中有一个 reply
块,当您完成查询时,运行 它与您的数据一起存储在字典中。
reply(@{@"localMatchup": localMatchup});
我想你可以调用 handleWatchKitExtensionRequest 方法