gpt4 book ai didi

ios - 如何检查 Apple Store 上可用的更新并在 Objective C 中提供弹出窗口

转载 作者:行者123 更新时间:2023-12-01 17:47:52 25 4
gpt4 key购买 nike

我是 iOS 新手,在检查 Apple Store 可用的新更新时遇到问题。

有什么API可以检查吗?

最佳答案

喜欢

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

// Fabric implementation

[self needsUpdate:^(NSDictionary *dictionary) {
// you can use the dictionary here

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];

if ([dictionary[@"resultCount"] integerValue] == 1){
NSString* appStoreVersion = dictionary[@"results"][0][@"version"];
NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
if (![appStoreVersion isEqualToString:currentVersion]){
NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
[self showAlert];
}


}

// if you want to update UI or model, dispatch this to the main queue:
// dispatch_async(dispatch_get_main_queue(), {
// do your UI stuff here
// do nothing
// });
}];

}

出于引用目的,我从 here 中获取了答案
-(void)needsUpdate:(void (^)(NSDictionary * dictionary))completionHandler{

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {

NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

if (completionHandler) {
completionHandler(lookup);
}



}];

[task resume];



}

显示警报
-(void)showAlert
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"please update app" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Okay!" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
@try
{
NSLog(@"tapped ok");
BOOL canOpenSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings)
{
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/in/app/tvfplay/id1067732674?mt=8"];
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
}
@catch (NSException *exception)
{

}
}]];
UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
topWindow.rootViewController = [UIViewController new];
topWindow.windowLevel = UIWindowLevelAlert + 1;
[topWindow makeKeyAndVisible];
[topWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

}

关于ios - 如何检查 Apple Store 上可用的更新并在 Objective C 中提供弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42575838/

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