In IOS development, how does one implement automatic detection and update of apps? In ios development, how does one implement apps?

Source: Internet
Author: User

In IOS development, how does one implement automatic detection and update of apps? In ios development, how does one implement apps?

Implementation logic of automatic detection and update:

First github address: https://github.com/wolfhous/HSUpdateApp

1. Obtain the APP version number of the current project.

2. Get the AppStore project version number.

3. Compare the version number to implement the UPDATE function.


Source code:

1 / * *
2 * TianChao special detection app update
3 * /
4 -(void)hsUpdateApp
5 {
6 / / 2 get the current project version number first
7     NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
8     NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];
Nine
10 / / 3 get the app store version number from the network
11     NSError *error;
12     NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID]]] returningResponse:nil error:nil];
13     if (response == nil) {
14 nslog (@ "you are not connected to the network";
15         return;
16}
17     NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
18     if (error) {
19         NSLog(@"hsUpdateAppError:%@",error);
20         return;
21}
22 //    NSLog(@"%@",appInfoDic);
23     NSArray *array = appInfoDic[@"results"];
24     NSDictionary *dic = array[0];
25     NSString *appStoreVersion = dic[@"version"];
26 / / print version number
27 nslog (@ "current version No.:% @ \ n store version No.:% @", CurrentVersion, appstoreversion);
28 / / 4 if the current version number is less than the store version number, it will be updated
29     if([currentVersion floatValue] < [appStoreVersion floatValue])
30 {
31 UIAlertView * alert = [[UIAlertView alloc] initwithtitle: @ "version has update" message: [nsstring stringwithformat: @ "new version detected (% @), update?", appstoreversion] delegate: self cancelbuttontitle: @ "Cancel" otherbuttontiles: @ "update", nil];
32         [alert show];
33     }else{
34 nslog (@ "the version number seems to be larger than the store! No update is detected.);
35}
Thirty-six
37}
1 - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
2 {
3 / / 5 implementation jump to store for update
4     if(buttonIndex==1)
5 {
6 / / 6 add the address of the application in the app store here, which is convenient for users to update. One implementation method is as follows:
7         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&amp;mt=8", STOREAPPID]];
8         [[UIApplication sharedApplication] openURL:url];
9}
10}

Then, in the window where you want to check for updates:

1 // check and update a code sentence 
2 [self hsUpdateApp];

Attachment: The STOREAPPID macro defines the ID number of your app in the store, which is a string of numbers. One method is to log on to itunesconnect to view the number, and the other method is Baidu or google.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.