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

标签 ios objective-c

我是 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/

相关文章:

objective-c - 用长整数制作唯一可读的字符串

ios - swift spritekit Facebook 分享按钮

objective-c - 如何在 OS X 中使用 objective c 获取父进程 ID?

iPhone iOS 如何向按钮文本或图像下的 UIButton 添加线性渐变?

ios - 我以编程方式创建了矩形,并在 Storyboard上添加了按钮,按钮被矩形覆盖了。我该如何解决?

ios - 我可以在 Realm 的线程中使用被忽略的属性吗?

ios - 从 block 内部获取变量

ios - 退出 iOS 应用程序(.monotouch-32 符号链接(symbolic link))

iphone 开发 : using tableview cells as a button

objective-c - 在 iOS 中以编程方式实例化类