1. 在AppStore上線的應(yīng)用(個(gè)人或者公司賬號(hào) 99美元)
在AppDelegate.m中調(diào)用?
/**
* 版本升級(jí)
*/
[self versionCheckAndUpdate];
實(shí)現(xiàn):
- (void)versionCheckAndUpdate {
// 獲取當(dāng)前版本 ?只需要Version喜颁,不需要Bulid
NSString *newVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSLog(@"%@", newVersion);
// 獲取 AppStore版本號(hào)
NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", @"1136975672"];
[self getAppStoreVersionWithpath:urlStr completionHandler:^(NSString *version) {
if (![version isEqualToString:@""]) {
if (![version isEqualToString:newVersion]) {
NSLog(@"有新版本了");
}
} else {
NSLog(@"AppStore沒(méi)有版本");
}
}];
}
#pragma mark -- 獲取數(shù)據(jù) --
- (void)getAppStoreVersionWithpath:(NSString *)path completionHandler:(void(^)(NSString *version))completionHandler {
// 使用NSURLSession去請(qǐng)求蘋果給的接口手负,會(huì)有很多信息,只取version
NSURL *url = [NSURL URLWithString:path];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10];
[request setHTTPMethod:@"POST"];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
if ([[resultDic valueForKey:@"resultCount"] intValue]>0) {
NSString *version = [[[resultDic valueForKey:@"results"] firstObject] valueForKey:@"version"];
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(version);
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(@"");
});
}
}] resume];
}
2. 企業(yè)應(yīng)用 (299美元)
a. 之前可以用友盟共郭,現(xiàn)在貌似新用戶用不了税稼;
b. 說(shuō)到底肝匆,我們只需要一個(gè)當(dāng)前用戶正在使用的版本的版本號(hào)懂讯,然后和當(dāng)前的版本號(hào)比較坛悉。寫個(gè)簡(jiǎn)單的接口伐厌,讓后臺(tái)返回就行?