iOS—应用检查更新的最优方法
2014-05-13 09:35
344 查看
虽然App Store能够提醒用户软件更新,但很多用户不会主动去更新一大堆的软件(我机器上待更新的软件在100个左右)。如果在软件开启时提醒用户更新 或者 更多中设置“检查更新”项,效果会好很多。
通常的做法是在自己的服务器上记录最新版本号,从iOS客户端请求,与本地版本号比较,不同则提示更新。这种做法简单,缺点是需要单独的服务器支持。
通过查阅相关文章,找到了如下方法,与上述方法类似,不过不需要另外的服务器支持。此为检查更新的最优方法。
[html] view
plaincopy
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];
}
[html] view
plaincopy
- (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返回的数据为:
[html] view
plaincopy
{
"resultCount":1,
"results": [
{"kind":"software", "features":["iosUniversal"], "supportedDevices":["all"], "isGameCenterEnabled":false,
"screenshotUrls":["http://a2.mzstatic.com/us/r1000/113/Purple/99/f8/ea/mzl.dcxkisqn.png", "http://a3.mzstatic.com/us/r1000/119/Purple/63/7f/c2/mzl.qybzxzxq.png", "http://a1.mzstatic.com/us/r1000/092/Purple/16/8a/13/mzl.fywgpbnb.png", "http://a2.mzstatic.com/us/r1000/103/Purple/b3/90/2e/mzl.xlpzzirl.png", "http://a4.mzstatic.com/us/r1000/069/Purple/f4/07/0b/mzl.cynatymj.png"],
"ipadScreenshotUrls":["http://a2.mzstatic.com/us/r1000/114/Purple/v4/9e/9e/fd/9e9efd78-7a57-89dc-9c13-e0a3c01af95b/mza_382609288154297810.1024x1024-65.jpg", "http://a4.mzstatic.com/us/r1000/084/Purple/v4/7a/f7/78/7af778c9-1546-ddeb-b5de-b577b703e28c/mza_8776755316162530832.1024x1024-65.jpg", "http://a2.mzstatic.com/us/r1000/111/Purple/v4/8e/49/7b/8e497b65-923d-715e-42b3-1b671841ee7d/mza_3991863266621328291.1024x1024-65.jpg", "http://a3.mzstatic.com/us/r1000/063/Purple/v4/6a/d4/f3/6ad4f3e4-7e73-be6e-f585-37eb65b0f812/mza_7049654211100682802.1024x1024-65.jpg", "http://a2.mzstatic.com/us/r1000/118/Purple/v4/d9/79/6f/d9796f55-a73a-f570-c20a-3594d5a49bdc/mza_6340688527152336903.1024x1024-65.jpg"], "artworkUrl60":"http://a3.mzstatic.com/us/r1000/069/Purple/a8/e3/35/mzi.swfjtgvw.png", "artworkUrl512":"http://a4.mzstatic.com/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.mzstatic.com/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, 与本地客户端版本号比较,即可判断有无更新。
原文摘自:http://blog.csdn.net/wave_1102/article/details/7463697
通常的做法是在自己的服务器上记录最新版本号,从iOS客户端请求,与本地版本号比较,不同则提示更新。这种做法简单,缺点是需要单独的服务器支持。
通过查阅相关文章,找到了如下方法,与上述方法类似,不过不需要另外的服务器支持。此为检查更新的最优方法。
[html] view
plaincopy
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];
}
[html] view
plaincopy
- (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返回的数据为:
[html] view
plaincopy
{
"resultCount":1,
"results": [
{"kind":"software", "features":["iosUniversal"], "supportedDevices":["all"], "isGameCenterEnabled":false,
"screenshotUrls":["http://a2.mzstatic.com/us/r1000/113/Purple/99/f8/ea/mzl.dcxkisqn.png", "http://a3.mzstatic.com/us/r1000/119/Purple/63/7f/c2/mzl.qybzxzxq.png", "http://a1.mzstatic.com/us/r1000/092/Purple/16/8a/13/mzl.fywgpbnb.png", "http://a2.mzstatic.com/us/r1000/103/Purple/b3/90/2e/mzl.xlpzzirl.png", "http://a4.mzstatic.com/us/r1000/069/Purple/f4/07/0b/mzl.cynatymj.png"],
"ipadScreenshotUrls":["http://a2.mzstatic.com/us/r1000/114/Purple/v4/9e/9e/fd/9e9efd78-7a57-89dc-9c13-e0a3c01af95b/mza_382609288154297810.1024x1024-65.jpg", "http://a4.mzstatic.com/us/r1000/084/Purple/v4/7a/f7/78/7af778c9-1546-ddeb-b5de-b577b703e28c/mza_8776755316162530832.1024x1024-65.jpg", "http://a2.mzstatic.com/us/r1000/111/Purple/v4/8e/49/7b/8e497b65-923d-715e-42b3-1b671841ee7d/mza_3991863266621328291.1024x1024-65.jpg", "http://a3.mzstatic.com/us/r1000/063/Purple/v4/6a/d4/f3/6ad4f3e4-7e73-be6e-f585-37eb65b0f812/mza_7049654211100682802.1024x1024-65.jpg", "http://a2.mzstatic.com/us/r1000/118/Purple/v4/d9/79/6f/d9796f55-a73a-f570-c20a-3594d5a49bdc/mza_6340688527152336903.1024x1024-65.jpg"], "artworkUrl60":"http://a3.mzstatic.com/us/r1000/069/Purple/a8/e3/35/mzi.swfjtgvw.png", "artworkUrl512":"http://a4.mzstatic.com/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.mzstatic.com/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, 与本地客户端版本号比较,即可判断有无更新。
原文摘自:http://blog.csdn.net/wave_1102/article/details/7463697
相关文章推荐
- (iPhone/iPad开发)iOS应用检查更新的最优方法
- IOS问题汇总:2014-12-11 iOS应用检查更新的最优方法附代码(转)+在 iOS 应用中直接跳转到 AppStore 的方法
- iOS应用检查更新的最优方法
- iOS应用检查更新的最优方法附代码
- iOS应用检查更新的最优方法
- iOS应用检查更新的最优方法
- iOS应用检查更新的最优方法
- iOS应用自动检查更新提示方法
- IOS应用版本更新如果保留检查更新入口审核时将被拒绝
- iOS开发:2017 苹果APP上架更新应用版本注意事项及APP版本迭代步骤方法
- ios 应用检查更新
- IOS中打开应用实现检查更新的功能
- iOS检查更新的方法
- IOS检查更新的方法
- IE/Firefox每次刷新时自动检查网页更新,无需手动清空缓存的设置方法(转)
- iOS 版本检测更新方法
- iOS 应用获取最上层全屏 Window 的正确方法
- IOS 版本检查更新
- ios更新UI时请尝试使用performSelectorOnMainThread方法
- Android系统切换语言更新应用界面方法