Reputation: 979
I am new in iOS and I am facing problem regarding to check new update available to Apple Store.
Is there is any API to check?
Upvotes: 1
Views: 2612
Reputation: 82759
do like
- (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
// });
}];
}
for reference purpose I taken the answer from 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];
}
show the alert
-(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];
}
Upvotes: 6
Reputation: 8351
There is no direct API
available for app update checking but you can check current version to iTune version.
Please check below links for the same :
SO Answer's:
IOS app update check within application
Check if my app has a new version on AppStore
There is also one library for checking update :
https://github.com/nicklockwood/iVersion
Hope this will helps you to check your app update.
Upvotes: 1