|
雖然App Store能夠提醒用戶軟件更新,但很多用戶不會主動去更新一大堆的軟件(我機(jī)器上待更新的軟件在100個左右)。如果在軟件開啟時提醒用戶更新 或者 更多中設(shè)置“檢查更新”項(xiàng),效果會好很多。
通常的做法是在自己的服務(wù)器上記錄最新版本號,從iOS客戶端請求,與本地版本號比較,不同則提示更新。這種做法簡單,缺點(diǎn)是需要單獨(dú)的服務(wù)器支持。
通過查閱相關(guān)文章,找到了如下方法,與上述方法類似,不過不需要另外的服務(wù)器支持。此為檢查更新的最優(yōu)方法。
- NSString *version = @"";
- NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=<Your app ID>"];
- versionRequest = [ASIFormDataRequest requestWithURL:url];
- [versionRequest setRequestMethod:@"GET"];
- [versionRequest setDelegate:self];
- [versionRequest setTimeOutSeconds:150];
- [versionRequest addRequestHeader:@"Content-Type" value:@"application/json"];
- [versionRequest startSynchronous];
-
- //Response string of our REST call
- NSString* jsonResponseString = [versionRequest responseString];
-
- NSDictionary *loginAuthenticationResponse = [jsonResponseString objectFromJSONString];
-
- NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];
-
- for (id config in configData)
- {
- version = [config valueForKey:@"version"];
- }
- //Check your version with the version in app store
- if (![version isEqualToString:[itsUserDefaults objectForKey:@"version"]])
- {
- ProAlertView *createUserResponseAlert = [[ProAlertView alloc] initWithTitle:@"New Version!!" message: @"A new version of app is available to download" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"Download", nil];
- [createUserResponseAlert show];
- [createUserResponseAlert release];
- }
- - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
- // the user clicked one of the OK/Cancel buttons
- if (buttonIndex == 1)
- {
- NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=<appid>&mt=8";
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
- }
- }
以Remote (http://itunes.apple.com/app/remote/id284417350?mt=8) 軟件為例,請求http://itunes.apple.com/lookup?id=284417350返回的數(shù)據(jù)為:
- {
- "resultCount":1,
- "results": [
- {"kind":"software", "features":["iosUniversal"], "supportedDevices":["all"], "isGameCenterEnabled":false,
- "screenshotUrls":["http://a2./us/r1000/113/Purple/99/f8/ea/mzl.dcxkisqn.png", "http://a3./us/r1000/119/Purple/63/7f/c2/mzl.qybzxzxq.png", "http://a1./us/r1000/092/Purple/16/8a/13/mzl.fywgpbnb.png", "http://a2./us/r1000/103/Purple/b3/90/2e/mzl.xlpzzirl.png", "http://a4./us/r1000/069/Purple/f4/07/0b/mzl.cynatymj.png"],
- "ipadScreenshotUrls":["http://a2./us/r1000/114/Purple/v4/9e/9e/fd/9e9efd78-7a57-89dc-9c13-e0a3c01af95b/mza_382609288154297810.1024x1024-65.jpg", "http://a4./us/r1000/084/Purple/v4/7a/f7/78/7af778c9-1546-ddeb-b5de-b577b703e28c/mza_8776755316162530832.1024x1024-65.jpg", "http://a2./us/r1000/111/Purple/v4/8e/49/7b/8e497b65-923d-715e-42b3-1b671841ee7d/mza_3991863266621328291.1024x1024-65.jpg", "http://a3./us/r1000/063/Purple/v4/6a/d4/f3/6ad4f3e4-7e73-be6e-f585-37eb65b0f812/mza_7049654211100682802.1024x1024-65.jpg", "http://a2./us/r1000/118/Purple/v4/d9/79/6f/d9796f55-a73a-f570-c20a-3594d5a49bdc/mza_6340688527152336903.1024x1024-65.jpg"], "artworkUrl60":"http://a3./us/r1000/069/Purple/a8/e3/35/mzi.swfjtgvw.png", "artworkUrl512":"http://a4./us/r1000/061/Purple/2c/a0/b7/mzl.lusstdyg.png", "artistViewUrl":"http://itunes.apple.com/us/artist/apple/id284417353?mt=12&uo=4", "artistId":284417353, "artistName":"Apple", "price":0.00, <span style="color: rgb(255, 0, 0); ">"version":"2.3"</span>,
- "description":"Control iTunes and Apple TV using your iPhone, iPad, or iPod touch over your Wi-Fi network. Choose playlists, songs, and albums as if you were in front of your computer or Apple TV. Or play them from iCloud with iTunes Match on Apple TV. From anywhere in your home, you can change a song, pick a playlist, or browse your entire library. With a flick of your finger, you can control the Apple TV interface. Use your iOS device's keyboard to quickly tap out a title instead of clicking letters on the Apple TV screen. Then keep tapping to play, fast-forward, rewind, and pause to your finger\u2019s content. Remote is fully optimized for the stunning Retina display in iPhone, iPad, and iPod touch and is designed to take advantage of the large Multi-Touch display on iPad. \n\nFeatures\n\u2022 Control iTunes and Apple TV from anywhere in your home\n\u2022 Browse, listen to, and control your iTunes Match library on Apple TV\n\u2022 Pause, rewind, fast-forward, shuffle, and adjust the volume from your iPhone, iPad, or iPod touch\n\u2022 View album, movie, and TV show artwork\n\u2022 Create and update iTunes playlists, including Genius playlists\n\u2022 Search your entire iTunes library\n\u2022 Control iTunes to send music to AirPlay speakers\n\u2022 Control the volume on each speaker independently\n\u2022 Use simple gestures to control Apple TV\n\u2022 Enter text with the keyboard\n\u2022 Control shared libraries on iTunes and the new Apple TV", "genreIds":["6016", "6011"], "releaseDate":"2008-07-11T07:00:00Z", "sellerName":"Apple Inc.", "currency":"USD", "genres":["Entertainment", "Music"], "bundleId":"com.apple.Remote", "trackId":284417350, "trackName":"Remote", "primaryGenreName":"Entertainment", "primaryGenreId":6016, "releaseNotes":"\u2022 Support for iTunes Match on Apple TV\n\u2022 Support for Retina display on iPad", "wrapperType":"software", "trackCensoredName":"Remote",
- "languageCodesISO2A":["AR", "CA", "CS", "DA", "DE", "EL", "EN", "ES", "FI", "FR", "HR", "HU", "ID", "IT", "HE", "JA", "KO", "MS", "NL", "NO", "PL", "PT", "RO", "RU", "SK", "SV", "TH", "TR", "UK", "VI", "ZH"], "fileSizeBytes":"21992445", "sellerUrl":"http://www.apple.com/itunes/remote", "contentAdvisoryRating":"4+", "averageUserRatingForCurrentVersion":3.5, "userRatingCountForCurrentVersion":794, "artworkUrl100":"http://a4./us/r1000/061/Purple/2c/a0/b7/mzl.lusstdyg.png", "trackViewUrl":"http://itunes.apple.com/us/app/remote/id284417350?mt=8&uo=4", "trackContentRating":"4+", "averageUserRating":3.5, "userRatingCount":197847}]
- }
請求出的version為2.3, 與本地客戶端版本號比較,即可判斷有無更新。
|