当我的应用在iTunes商店中有新版本时,是否可以强制用户进行升级?
我目前正在开发一个应用程序。但是每次我上传一个新版本时,我希望能够强制用户进行升级,因为新版本拥有更多功能,而我想丢弃旧版本。 iPhone 默认是否支持此操作,还是我需要编写自己的实现来检查当前版本并将其与商店进行比较?
当我的应用在iTunes商店中有新版本时,是否可以强制用户进行升级?
我目前正在开发一个应用程序。但是每次我上传一个新版本时,我希望能够强制用户进行升级,因为新版本拥有更多功能,而我想丢弃旧版本。 iPhone 默认是否支持此操作,还是我需要编写自己的实现来检查当前版本并将其与商店进行比较?
我通过从iTunes网络服务获取版本并与当前版本进行比较来完成此功能...以下是我的代码
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];
}
将应用程序 ID 放入 iTunes 链接中,请参见下面的代码...
- (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]];
}
}
注意:您需要使用JSONKit框架和ASIHttp框架来进行Web服务调用。
[NSData dataWithContentsOfURL:url]
。但是请使用上面提到的lookup?id=<Your app ID>
而不是datinc的`lookup?bundleid=..". - ToolmakerSteve您可以检测应用程序是否需要更新,然后执行一些自定义操作,例如提醒用户有更新可用。以下是一段检测更新的代码片段。
-(BOOL) needsUpdate{
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([lookup[@"resultCount"] integerValue] == 1){
NSString* appStoreVersion = lookup[@"results"][0][@"version"];
NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
if (![appStoreVersion isEqualToString:currentVersion]){
NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
return YES;
}
}
return NO;
}
lookup?bundleId=
替换为lookup?id=
。 并使用您的应用程序的“Apple ID”,而不是查找捆绑标识符。 因此,在url =
之前的两行无需;只需在您的应用程序的iTunes连接页面上硬编码“Apple ID”。 - ToolmakerSteve[appStoreVersion compare:currentVersion options:NSNumericSearch] == NSOrderedDescending
的方法来比较两个版本可能也是可取的,例如如果您想避免潜在的App Store审核问题,因为正在审核的版本将始终与App Store版本不同。当然,这仅适用于每次发布都增加版本号(而不是从版本2.0.0到1.0.0)。 - DARKMATTERpod 'Siren'
Carthage:
github "ArtSabintsev/Siren"
如果你非常必要,可以启动应用商店,让你的用户可以从中获取最新版本。我建议将此作为可选项,或者至少先呈现对话框。
// iTunesLink should be your applications link
NSString *iTunesLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
没有自动化的方法可以完成这个任务,您需要手动编写代码。
*编辑* 这个答案已经不正确了。请查看其他赞同的答案以获取当前的真相。
这里是 GitHub 上的链接:https://github.com/SlalomDigital/ApplicationCtrl
贡献并帮助我彻底解决这个问题!
我的应用更新在应用商店被拒绝,原因就是这个。我们添加了一个功能来检查已安装版本和当前版本的差异,如果不支持该版本,我们会强制用户更新。
苹果公司拒绝了这个功能。
所以只能回到设计阶段重新规划!