Check If My iOS Application Is Updated

Check if my IOS application is updated

You could save a value (e.g. the current app version number) to NSUserDefaults and check it every time the user starts the app.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *currentAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *previousVersion = [defaults objectForKey:@"appVersion"];
if (!previousVersion) {
// first launch

// ...

[defaults setObject:currentAppVersion forKey:@"appVersion"];
[defaults synchronize];
} else if ([previousVersion isEqualToString:currentAppVersion]) {
// same version
} else {
// other version

// ...

[defaults setObject:currentAppVersion forKey:@"appVersion"];
[defaults synchronize];
}

return YES;
}

The swift-2 version looks like this:

let defaults = NSUserDefaults.standardUserDefaults()

let currentAppVersion = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
let previousVersion = defaults.stringForKey("appVersion")
if previousVersion == nil {
// first launch
defaults.setObject(currentAppVersion, forKey: "appVersion")
defaults.synchronize()
} else if previousVersion == currentAppVersion {
// same version
} else {
// other version
defaults.setObject(currentAppVersion, forKey: "appVersion")
defaults.synchronize()
}

The swift-3 version looks like this:

let defaults = UserDefaults.standard

let currentAppVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
let previousVersion = defaults.string(forKey: "appVersion")
if previousVersion == nil {
// first launch
defaults.set(currentAppVersion, forKey: "appVersion")
defaults.synchronize()
} else if previousVersion == currentAppVersion {
// same version
} else {
// other version
defaults.set(currentAppVersion, forKey: "appVersion")
defaults.synchronize()
}

How To check if there is a new version of my app in the App Store on Swift5?

Yes, the method you use must be an already published app.

If you use an unpublished app, you will get results = []

Go to the App Store like this

let appId = "1454358806" // Replace with your appId
let appURL = URL.init(string: "itms-apps://itunes.apple.com/cn/app/id" + appId + "?mt=8") //Replace cn for your current country

UIApplication.shared.open(appURL!, options:[.universalLinksOnly : false]) { (success) in

}

Note:

This method will not be very timely, meaning that the application you just released, even if it can be searched in the App store, but results will not be updated immediately. Update information will be available after approximately 1 hour, or longer

Check if my iOS application can be force updated

While you can't actually force the upgrade, a typical solution here is to provide an alert with a button taking the user to the app's AppStore URL, which will prompt them to update the app. This alert can be triggered on every app launch such that the user cannot get into the app without installing the upgrade.

How to detect an iOS App installed or upgraded?

You can differentiate between the first start after installing the App, the first start after an update and other starts quite easily via saving the latest known version to standardUserDefaults. But as far as I know it is not possible do detect a re-install of the App as all App-related data are also removed when the App is deleted from the device.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString* currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString* versionOfLastRun = [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionOfLastRun"];

if (versionOfLastRun == nil) {
// First start after installing the app
} else if (![versionOfLastRun isEqual:currentVersion]) {
// App was updated since last run
} else {
// nothing changed
}

[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"VersionOfLastRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

How to tell if an iOS application has been newly installed or updated?

You could save a version number to NSUserDefaults, and update it accordingly.

If that won't work, you may be able to release an intermediate version which introduces the versioning scheme.

If that's not an option, you may be able to check for traces of previous runs from files you create, or preferences which you set conditionally or lazily.

How to check update Available on Apple Store and give popup in Objective C

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];

}


Related Topics



Leave a reply



Submit