IOS development beginner: Update reminder in-app

Source: Internet
Author: User

Currently, the vast majority of applications can be updated, and you will receive an update notification when you open the application. This is conducive to user updates.

Many people want xcode to provide corresponding APIs to find the application version. However, there is no such API yet. Therefore, there are two solutions:

1. Set up your own server. After the application is updated, update the version information on your server. Then, connect the application to the server to find the version information and check it against the current application version, prompt if update

2. Use the search-API of App Store to obtain the corresponding application information through the corresponding API. The key is the JSON format, therefore, we can extract and compare the version information. The URL is as follows:

Http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

As you can see, just use https://itunes.apple.com/lookup? For a URL such as ID = 595176741, replace the ID with the ID of the application, and then you can get the information in JSON format.

The following JSON information can be obtained through the application of the 3D plug-in as an example:

{ "resultCount":1, "results": [{"kind":"software", "features":["iosUniversal"], "supportedDevices":["iPodTouchourthGen", "iPad2Wifi", "iPad23G", "iPhone4"], "isGameCenterEnabled":false, "artistViewUrl":"https://itunes.apple.com/us/artist/hongkun-song/id595176744?uo=4", "artworkUrl60":"http://a86.phobos.apple.com/us/r1000/091/Purple2/v4/0a/db/51/0adb5130-5d18-0b98-d1cc-3ddd114b10d5/icon57_57.png", "screenshotUrls":["http://a1960.phobos.apple.com/us/r1000/108/Purple/v4/ea/52/80/ea52802a-c7d9-1dca-defe-937fb61bbc3e/mzl.ghupvxyw.png", "http://a1740.phobos.apple.com/us/r1000/110/Purple2/v4/58/40/64/584064d8-1d3b-6704-3bf7-3b1c771d25c1/mzl.ydpovfzk.png", "http://a180.phobos.apple.com/us/r1000/100/Purple2/v4/22/01/90/22019008-314d-07e7-49e4-2359983058c0/mzl.hefjpqiw.png", "http://a1862.phobos.apple.com/us/r1000/107/Purple/v4/ee/23/a6/ee23a69f-768f-5fe8-9444-298a26330faa/mzl.sxiofdqt.png", "http://a980.phobos.apple.com/us/r1000/102/Purple/v4/cd/2c/9f/cd2c9fff-8dac-b75d-f260-c223ea8d2b33/mzl.trozlblw.png"], "ipadScreenshotUrls":["http://a651.phobos.apple.com/us/r1000/079/Purple/v4/e9/ab/55/e9ab55ab-6b7c-04ab-034e-833c113be412/mzl.ganeacuj.1024x1024-65.jpg", "http://a247.phobos.apple.com/us/r1000/107/Purple/v4/f3/87/60/f3876038-162a-7df4-87e5-54b6a5b14b78/mzl.vxycagic.1024x1024-65.jpg", "http://a831.phobos.apple.com/us/r1000/093/Purple2/v4/8b/b3/77/8bb37753-e3d5-9f45-ecfb-bf09cdb660f0/mzl.ncygstwb.1024x1024-65.jpg", "http://a376.phobos.apple.com/us/r1000/078/Purple/v4/f3/4e/36/f34e362f-dee0-0903-436e-034ba94a6f79/mzl.ecchwkyv.1024x1024-65.jpg", "http://a1624.phobos.apple.com/us/r1000/079/Purple/v4/db/12/9d/db129d6b-107b-fa80-f472-a8c7809ef513/mzl.xjmeijfn.1024x1024-65.jpg"], "artworkUrl512":"http://a1435.phobos.apple.com/us/r1000/076/Purple/v4/d1/36/f5/d136f5d0-3962-9ba1-95b2-3ca0ba3be9ec/mzl.zzqaoikx.jpg", "artistId":595176744, "artistName":"Hongkun Song", "price":1.99, "version":"2.0", "description":"Measure actual angles from a distance? This magical App makes impossible happen!\n\nJust throw your plastic protractor away if you have an iPhone! I think you would never have to use traditional protractors any more! Since here is a much better tool for you to measure angles, that is your iOS device and of course, with the amazing app 3D Protractor!\n\n3D Protractor! A super tool for you to measure all kinds of angles in the 3D space by moving and rotating your iOS device or using the camera!\n\nDon\u2019t limit your imagination of measuring angles to just measuring the angle between two lines on a plane! This was an old thinking. 3D Protractor breaks it! In fact,it is so powerful that it can do following five jobs:\n1,Line-Line Angle Measurement. It can measure the angle of any two lines in the space,include the angle on a plane.\n2,Slope Angle Measurement. \n3,Dihedral Angle Measurement.\n4,Line-Face Angle Measurement.\n\n5,Camera Angle Measurement. It is a super cool feature! It can measure actual angles of any objects in front by the device's camera. Unbelievable! Actual angle! \n\nYou might feel a little bit confused at first after reading the above professional descriptions. This App uses 3D models to make it really easy for you to understand and use.\nEveryone can use it. Students can use it to do their homework. Teachers can use it to teach geometry especially solid geometry, which makes a really good teaching tool. Engineers can use it to measure any angles they need to know at work. And of course, there are many many more usages in our daily life.\n\n3D Protractor! Re-invention of protractor! \nA great app to make measuring angle easy and more accurate! \nA great app to change the world of angle measurement!\n\nPS. 1、If you measure an angle in a long time,the precision may be lower.\n2、This version has no Ads!", "currency":"USD", "genres":["Utilities", "Education"], "genreIds":["6002", "6017"], "releaseDate":"2013-01-26T07:54:39Z", "sellerName":"Hongkun Song", "bundleId":"com.manmanlai.-D-Protractor", "trackId":595176741, "trackName":"3D Protractor", "primaryGenreName":"Utilities", "primaryGenreId":6002, "releaseNotes":"1、Add Camera Angle Measurement Feature; \nIt is a super cool feature! It can measure actual angles of any objects in front by the device's camera. Unbelievable! Actual angle!\n2、Add radian number display; \nTap the number, then you would see the transition between degree and radian number. \n3、Add traditional chinese version; \n4、Fix some bugs;", "formattedPrice":"$1.99", "wrapperType":"software", "trackCensoredName":"3D Protractor", "trackViewUrl":"https://itunes.apple.com/us/app/3d-protractor/id595176741?mt=8&uo=4", "contentAdvisoryRating":"4+", "artworkUrl100":"http://a1435.phobos.apple.com/us/r1000/076/Purple/v4/d1/36/f5/d136f5d0-3962-9ba1-95b2-3ca0ba3be9ec/mzl.zzqaoikx.jpg", "languageCodesISO2A":["ZH", "EN"], "fileSizeBytes":"14633609", "averageUserRatingForCurrentVersion":5.0, "userRatingCountForCurrentVersion":2, "trackContentRating":"4+", "averageUserRating":4.5, "userRatingCount":8}]}

It can be seen that there are all updated content, which is very easy. The specific implementation method is as follows:
NSString *query = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@", AppID];    query = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];    NSData *jsonData = [[NSString stringWithContentsOfURL:[NSURL URLWithString:query] encoding:NSUTF8StringEncoding error:nil] dataUsingEncoding:NSUTF8StringEncoding];    NSError *error = nil;    NSDictionary *results = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error] : nil;

After obtaining the results of nsdictionary, everything will be fine. Utf8string encoding is specially added to the Code. Of course, all JSON results are encoded on the webpage
As UTF-8.

In addition, you need to obtain the app version, as shown in the following code: [[nsbundle mainbundle] objectforinfodictionarykey: @ "cfbundle#versionstring"];
APP build version: [[nsbundle mainbundle] objectforinfodictionarykey: @ "cfbundleversion"];


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.