如何检查应用程序的版本并请求用户更新?
如何检查用户是否拥有我的应用程序的当前版本,并弹出一条消息以请求他们更新其应用程序版本?
就像您在下面看到的那样。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的服务器上需要有一个 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
(replacingAPPID
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要检查您是否拥有最新版本,只需使用以下查询在 iTunes 中查询应用程序数据(注意:更改 ID 以匹配来自 iTunesConnect 的应用程序 ID):
http://itunes.apple.com/lookup?id=520604518
这会返回一个 JSON 字典,非常简单要转换为 NSDictionary 以直接在代码中使用,那么您需要做的就是提取“version”键的值并将其与您的应用程序版本号进行比较(请参阅下面粗体显示的版本键/值):
以下是一些代码来完成这个任务。 -rh
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):
Here is some code to accomplish this task. -rrh