gpt4 book ai didi

ios - `UIApplicationDelegate` 到 `WKInterfaceController` 数据传递

转载 作者:行者123 更新时间:2023-11-28 19:51:15 27 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于ios - `UIApplicationDelegate` 到 `WKInterfaceController` 数据传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29112544/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com