如何检查应用程序的版本并请求用户更新?

发布于 2024-12-04 04:11:18 字数 141 浏览 3 评论 0原文

如何检查用户是否拥有我的应用程序的当前版本,并弹出一条消息以请求他们更新其应用程序版本?

就像您在下面看到的那样。

在此处输入图像描述

How can I check if the user has the current version of my app and also pop up a message to request them to update their app version?

Something like what you would see below.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离旧人 2024-12-11 04:11:18

您的服务器上需要有一个 WebService(或类似的东西),您的应用程序在启动时会请求该 WebService,以了解哪个是可用的最新版本。 (如果您还没有 WS 并且确实不想为此实现一个 WS,您也可以简单地使用也包含该版本的 XML 或文本文件)

然后将从服务器检索到的此版本与当前版本进行比较应用程序的,使用 [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]

如果它们不同,您可以显示警报视图并重定向到 itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=[APPID]&mt=8(将 APPID 替换为您的 iTunes Connect 应用 ID),该链接将使您的 iPhone 直接在应用程序的更新页面上打开 AppStore 应用程序

You need to have a WebService on your server (or something similar) that your app requests at startup, to know which is the latest version available. (If you don't have a WS yet and really don't want to implement one for that, you may also simply use an XML or text file that contains the version too)

Then compare this version retrieved from your server with the current version of the application, using [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"].

If they are different, you can display the alertview and redirect to itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=[APPID]&mt=8 (replacing APPID with your iTunes Connect App ID), which is the link that will make your iPhone open the AppStore application directly on your application's update page

风尘浪孓 2024-12-11 04:11:18

要检查您是否拥有最新版本,只需使用以下查询在 iTunes 中查询应用程序数据(注意:更改 ID 以匹配来自 iTunesConnect 的应用程序 ID):

http://itunes.apple.com/lookup?id=520604518

这会返回一个 JSON 字典,非常简单要转换为 NSDictionary 以直接在代码中使用,那么您需要做的就是提取“version”键的值并将其与您的应用程序版本号进行比较(请参阅下面粗体显示的版本键/值):

{
    "resultCount": 1,
    "results": [
        {
            "kind": "software",
            "features": [],
            "supportedDevices": [
                "all"
            ],
            "isGameCenterEnabled": false,
            "artistViewUrl": "https://itunes.apple.com/us/artist/d-m-holdings/id388608883?uo=4",
            "artworkUrl60": "http://a899.phobos.apple.com/us/r1000/086/Purple/v4/6d/b3/05/6db305aa-c685-558b-8c8e-8b7245375ce1/IconAudio.png",
            "screenshotUrls": [
                "http://a86.phobos.apple.com/us/r1000/078/Purple/v4/8f/ff/47/8fff4783-f2e4-fe3f-ef92-96d67d66c12b/mzl.dwbdvxny.png",
                "http://a731.phobos.apple.com/us/r1000/097/Purple/v4/cb/65/f6/cb65f613-408a-dffe-fb36-165db0c1a360/mzl.jexyhdnq.png",
                "http://a940.phobos.apple.com/us/r1000/097/Purple/v4/f6/26/a1/f626a18c-691f-7345-8d3d-f19713144818/mzl.llsgsagl.png",
                "http://a185.phobos.apple.com/us/r1000/071/Purple/v4/7d/5e/bc/7d5ebcad-7755-e772-727c-65de99effd60/mzl.zuyvhebk.png",
                "http://a48.phobos.apple.com/us/r1000/096/Purple/v4/d6/f5/f1/d6f5f108-10ab-3738-26cf-5ce82c6bb690/mzl.ijtyynie.png"
            ],
            "ipadScreenshotUrls": [],
            "artworkUrl512": "http://a672.phobos.apple.com/us/r1000/100/Purple/v4/e3/cb/5d/e3cb5d2d-f1a8-8b80-3a91-58be8f654710/mzm.uogqezwx.png",
            "artistId": 388608883,
            "artistName": "D&M Holdings",
            "price": 0,
            **"version": "1.0.5",**
            "description": "Designed to enhance the listening experience with Denon’s new line of Music Maniac™ headphones, the Denon Audio app is designed for the on-the-go audiophile. The Denon Audio app features a premium audio player that lets you experience the best possible sound quality from your iPod music library and favorite Internet radio stations. Create & save custom EQ curves, create & save instant playlists, enjoy internet radio stations via the built-in TuneIn service, and more. The Denon Audio app will quickly replace all of your other music apps.\n \nThe Denon Audio app features a customizable graphical equalizer that lets you contour your own sound by directly manipulating more than 1000 discrete bands of equalization without adding spatial distortion or decreasing sound quality. Pump up the bass, restore those highs, and start jammin’! \n \nEQ FEATURES:\n \n• Graphical equalizer for your iPod music library and streaming Internet Radio\n• 1000 possible discrete bands\n• 10 built in EQ Presets\n• Create and save your own EQ Presets\n• Bypass mode to quickly compare the original and equalized audio\n• Real-time spectrum analyzer\n• Linear phase design\n• No spatial distortion\n\nIPOD MUSIC LIBRARY FEATURES:\n\n• Enhances your listening experience with Denon Music Maniac Headphones or other audio playback devices such as docking stations, a/v receivers, car stereos via USB, Bluetooth, or Airplay.\n• Powerful queue based playback system lets you build and order your own playlist on the fly.\n• Save the playback queue as a new playlist\n• A single song, all songs on an album, all songs by an artist, and all songs in a genre can easily be added to the now playing queue.\n• Supports both portrait and landscape modes for browsing, playing, and equalizing\n• Shuffle and repeat playback modes\n• iPod library browsing by Playlist, Artist, Album, Song, Genre, Composer, Compilation, and Podcast (no importing needed)\n\nINTERNET RADIO FEATURES:\n\n• The TuneIn service provides global access to Internet radio – covering over 70,000 radio stations and 2 million on-demand programs including sports, news, talk, music and comedy. \n• Browse Internet radio stations by location, genre, language or Podcast (on-demand programs).\n• Powerful search feature for your iPod music library and Internet Radio \n• Save your favorite Internet Radio stations or programs as convenient presets and share them with  other TuneIn compatible devices\n• Ability to choose high or low quality streams offered by broadcasters\n \nADDITIONAL FEATURES:\n\n• Streams music over AirPlay to any Denon AirPlay compatible receiver or HiFi product\n• Share what you’re listening to via Facebook, Twitter, Email, or Text Message (iMessage)\n\nNOTICES:\n \n• The Denon Audio app requires iOS 5 or later and works with the iPhone 3GS or newer, the iTouch 3rd generation or newer, and all iPads (in 2x mode). \n• DRM protected iTunes music is NOT supported by the Denon Audio app (or any 3rd party music app)\n• iTunes Match will be supported in a future update \n• WiFi or data connection required to stream Internet radio",
            "currency": "USD",
            "genres": [
                "Music",
                "Lifestyle"
            ],
            "genreIds": [
                "6011",
                "6012"
            ],
            "releaseDate": "2012-05-29T07:00:00Z",
            "sellerName": "D&M Holdings Inc.",
            "bundleId": "com.dm-holdings.denon-audio",
            "trackId": 520604518,
            "trackName": "Denon Audio",
            "primaryGenreName": "Music",
            "primaryGenreId": 6011,
            "releaseNotes": "• Added 4\" display support for the iPhone 5 and 5th generation iPod Touch\n\n• Added an audio limiter function to protect against possible distortion introduced from pushing the EQ too high\n\n• Displays the Shuffle, Repeat, AirPlay, and Share icons as well as the scan/scrub controls on the \"Now Playing\" screen by default (so everyone knows they are included in the app). Tap the cover art to hide/show these controls",
            "formattedPrice": "Free",
            "wrapperType": "software",
            "trackCensoredName": "Denon Audio",
            "trackViewUrl": "https://itunes.apple.com/us/app/denon-audio/id520604518?mt=8&uo=4",
            "contentAdvisoryRating": "4+",
            "artworkUrl100": "http://a672.phobos.apple.com/us/r1000/100/Purple/v4/e3/cb/5d/e3cb5d2d-f1a8-8b80-3a91-58be8f654710/mzm.uogqezwx.png",
            "languageCodesISO2A": [
                "ZH",
                "DE",
                "EN",
                "ES",
                "FR",
                "JA",
                "NL"
            ],
            "fileSizeBytes": "9060882",
            "sellerUrl": "http://www.usa.denon.com/headphones",
            "averageUserRatingForCurrentVersion": 4.5,
            "userRatingCountForCurrentVersion": 329,
            "trackContentRating": "4+",
            "averageUserRating": 4.5,
            "userRatingCount": 471
        }
    ]
}

以下是一些代码来完成这个任务。 -rh

NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPSTORE_ID]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

[NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           if (!error) {
                               NSError* parseError;
                               NSDictionary *appMetadataDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&parseError];
                               NSArray *resultsArray = (appMetadataDictionary)?[appMetadataDictionary objectForKey:@"results"]:nil;
                               NSDictionary *resultsDic = [resultsArray firstObject];
                               if (resultsDic) {
                                   // compare version with your apps local version
                                   NSString *iTunesVersion = [resultsDic objectForKey:@"version"];

                                   NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)@"CFBundleShortVersionString"];
                                   if (iTunesVersion && [appVersion compare:iTunesVersion] != NSOrderedSame) { // new version exists
                                       // inform user new version exists, give option that links to the app store to update your app - see AliSoftware's answer for the app update link
                                       UIAlertView *alert = [UIAlertView bk_showAlertViewWithTitle:APP_NAME message:[NSString stringWithFormat:@"New version %@ available. Update required.",iTunesVersion] cancelButtonTitle:@"update" otherButtonTitles:nil handler:^(UIAlertView *alertView, NSInteger buttonIndex) {


                                        NSString *iTunesLink = [NSString stringWithFormat:@"itms://itunes.apple.com/us/app/apple-store/id%@?mt=8",APPSTORE_ID];
                                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
                                       }];
                                       [alert show];
                                   }
                               }
                           } else {
                               // error occurred with http(s) request
                               NSLog(@"error occurred communicating with iTunes");
                           }
                       }];

To check to see if you have the latest version just query iTunes for app data using the following query (note: change the id to match your app's id from iTunesConnect):

http://itunes.apple.com/lookup?id=520604518

This returns a JSON dictionary which is very easy to convert to an NSDictionary to use directly within your code, then all you need to do is pull out the value for the "version" key and compare it against your apps version number (see version key/value bolded below):

{
    "resultCount": 1,
    "results": [
        {
            "kind": "software",
            "features": [],
            "supportedDevices": [
                "all"
            ],
            "isGameCenterEnabled": false,
            "artistViewUrl": "https://itunes.apple.com/us/artist/d-m-holdings/id388608883?uo=4",
            "artworkUrl60": "http://a899.phobos.apple.com/us/r1000/086/Purple/v4/6d/b3/05/6db305aa-c685-558b-8c8e-8b7245375ce1/IconAudio.png",
            "screenshotUrls": [
                "http://a86.phobos.apple.com/us/r1000/078/Purple/v4/8f/ff/47/8fff4783-f2e4-fe3f-ef92-96d67d66c12b/mzl.dwbdvxny.png",
                "http://a731.phobos.apple.com/us/r1000/097/Purple/v4/cb/65/f6/cb65f613-408a-dffe-fb36-165db0c1a360/mzl.jexyhdnq.png",
                "http://a940.phobos.apple.com/us/r1000/097/Purple/v4/f6/26/a1/f626a18c-691f-7345-8d3d-f19713144818/mzl.llsgsagl.png",
                "http://a185.phobos.apple.com/us/r1000/071/Purple/v4/7d/5e/bc/7d5ebcad-7755-e772-727c-65de99effd60/mzl.zuyvhebk.png",
                "http://a48.phobos.apple.com/us/r1000/096/Purple/v4/d6/f5/f1/d6f5f108-10ab-3738-26cf-5ce82c6bb690/mzl.ijtyynie.png"
            ],
            "ipadScreenshotUrls": [],
            "artworkUrl512": "http://a672.phobos.apple.com/us/r1000/100/Purple/v4/e3/cb/5d/e3cb5d2d-f1a8-8b80-3a91-58be8f654710/mzm.uogqezwx.png",
            "artistId": 388608883,
            "artistName": "D&M Holdings",
            "price": 0,
            **"version": "1.0.5",**
            "description": "Designed to enhance the listening experience with Denon’s new line of Music Maniac™ headphones, the Denon Audio app is designed for the on-the-go audiophile. The Denon Audio app features a premium audio player that lets you experience the best possible sound quality from your iPod music library and favorite Internet radio stations. Create & save custom EQ curves, create & save instant playlists, enjoy internet radio stations via the built-in TuneIn service, and more. The Denon Audio app will quickly replace all of your other music apps.\n \nThe Denon Audio app features a customizable graphical equalizer that lets you contour your own sound by directly manipulating more than 1000 discrete bands of equalization without adding spatial distortion or decreasing sound quality. Pump up the bass, restore those highs, and start jammin’! \n \nEQ FEATURES:\n \n• Graphical equalizer for your iPod music library and streaming Internet Radio\n• 1000 possible discrete bands\n• 10 built in EQ Presets\n• Create and save your own EQ Presets\n• Bypass mode to quickly compare the original and equalized audio\n• Real-time spectrum analyzer\n• Linear phase design\n• No spatial distortion\n\nIPOD MUSIC LIBRARY FEATURES:\n\n• Enhances your listening experience with Denon Music Maniac Headphones or other audio playback devices such as docking stations, a/v receivers, car stereos via USB, Bluetooth, or Airplay.\n• Powerful queue based playback system lets you build and order your own playlist on the fly.\n• Save the playback queue as a new playlist\n• A single song, all songs on an album, all songs by an artist, and all songs in a genre can easily be added to the now playing queue.\n• Supports both portrait and landscape modes for browsing, playing, and equalizing\n• Shuffle and repeat playback modes\n• iPod library browsing by Playlist, Artist, Album, Song, Genre, Composer, Compilation, and Podcast (no importing needed)\n\nINTERNET RADIO FEATURES:\n\n• The TuneIn service provides global access to Internet radio – covering over 70,000 radio stations and 2 million on-demand programs including sports, news, talk, music and comedy. \n• Browse Internet radio stations by location, genre, language or Podcast (on-demand programs).\n• Powerful search feature for your iPod music library and Internet Radio \n• Save your favorite Internet Radio stations or programs as convenient presets and share them with  other TuneIn compatible devices\n• Ability to choose high or low quality streams offered by broadcasters\n \nADDITIONAL FEATURES:\n\n• Streams music over AirPlay to any Denon AirPlay compatible receiver or HiFi product\n• Share what you’re listening to via Facebook, Twitter, Email, or Text Message (iMessage)\n\nNOTICES:\n \n• The Denon Audio app requires iOS 5 or later and works with the iPhone 3GS or newer, the iTouch 3rd generation or newer, and all iPads (in 2x mode). \n• DRM protected iTunes music is NOT supported by the Denon Audio app (or any 3rd party music app)\n• iTunes Match will be supported in a future update \n• WiFi or data connection required to stream Internet radio",
            "currency": "USD",
            "genres": [
                "Music",
                "Lifestyle"
            ],
            "genreIds": [
                "6011",
                "6012"
            ],
            "releaseDate": "2012-05-29T07:00:00Z",
            "sellerName": "D&M Holdings Inc.",
            "bundleId": "com.dm-holdings.denon-audio",
            "trackId": 520604518,
            "trackName": "Denon Audio",
            "primaryGenreName": "Music",
            "primaryGenreId": 6011,
            "releaseNotes": "• Added 4\" display support for the iPhone 5 and 5th generation iPod Touch\n\n• Added an audio limiter function to protect against possible distortion introduced from pushing the EQ too high\n\n• Displays the Shuffle, Repeat, AirPlay, and Share icons as well as the scan/scrub controls on the \"Now Playing\" screen by default (so everyone knows they are included in the app). Tap the cover art to hide/show these controls",
            "formattedPrice": "Free",
            "wrapperType": "software",
            "trackCensoredName": "Denon Audio",
            "trackViewUrl": "https://itunes.apple.com/us/app/denon-audio/id520604518?mt=8&uo=4",
            "contentAdvisoryRating": "4+",
            "artworkUrl100": "http://a672.phobos.apple.com/us/r1000/100/Purple/v4/e3/cb/5d/e3cb5d2d-f1a8-8b80-3a91-58be8f654710/mzm.uogqezwx.png",
            "languageCodesISO2A": [
                "ZH",
                "DE",
                "EN",
                "ES",
                "FR",
                "JA",
                "NL"
            ],
            "fileSizeBytes": "9060882",
            "sellerUrl": "http://www.usa.denon.com/headphones",
            "averageUserRatingForCurrentVersion": 4.5,
            "userRatingCountForCurrentVersion": 329,
            "trackContentRating": "4+",
            "averageUserRating": 4.5,
            "userRatingCount": 471
        }
    ]
}

Here is some code to accomplish this task. -rrh

NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPSTORE_ID]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

[NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           if (!error) {
                               NSError* parseError;
                               NSDictionary *appMetadataDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&parseError];
                               NSArray *resultsArray = (appMetadataDictionary)?[appMetadataDictionary objectForKey:@"results"]:nil;
                               NSDictionary *resultsDic = [resultsArray firstObject];
                               if (resultsDic) {
                                   // compare version with your apps local version
                                   NSString *iTunesVersion = [resultsDic objectForKey:@"version"];

                                   NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)@"CFBundleShortVersionString"];
                                   if (iTunesVersion && [appVersion compare:iTunesVersion] != NSOrderedSame) { // new version exists
                                       // inform user new version exists, give option that links to the app store to update your app - see AliSoftware's answer for the app update link
                                       UIAlertView *alert = [UIAlertView bk_showAlertViewWithTitle:APP_NAME message:[NSString stringWithFormat:@"New version %@ available. Update required.",iTunesVersion] cancelButtonTitle:@"update" otherButtonTitles:nil handler:^(UIAlertView *alertView, NSInteger buttonIndex) {


                                        NSString *iTunesLink = [NSString stringWithFormat:@"itms://itunes.apple.com/us/app/apple-store/id%@?mt=8",APPSTORE_ID];
                                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
                                       }];
                                       [alert show];
                                   }
                               }
                           } else {
                               // error occurred with http(s) request
                               NSLog(@"error occurred communicating with iTunes");
                           }
                       }];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文