`UIApplicationDelegate`到`WKInterfaceController`数据传递

时间:2015-03-18 01:10:30

标签: ios objective-c parse-platform watchkit

有关如何将此数据从我的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});
            }
        }];
    }
}

很高兴发布任何额外的代码只是问,谢谢!

2 个答案:

答案 0 :(得分:2)

reply方法中有一个handleWatchKitExtensionRequest块,当您完成查询时,在dict中使用您的数据运行它。

reply(@{@"localMatchup": localMatchup});

答案 1 :(得分:1)

我认为你可以调用handleWatchKitExtensionRequest方法