iOS APP升级跳转到AppStore
2018-02-26 本文已影响1023人
huicuihui
本地检测版本,判断是否需要更新版本。如果需要的话就跳转到AppStore上。
首先讲一下如何获取AppStore上的地址:
记录一下:当iOS应用有提示升级功能,用户点击【升级】后直接打开AppStore显示该APP界面。
例如淘宝,从ituns里面复制的链接是:
[https://itunes.apple.com/cn/app/tao-bao-sui-shi-sui-xiang/id387682726?mt=8](https://itunes.apple.com/cn/app/tao-bao-sui-shi-sui-xiang/id387682726?mt=8)
image.png
需要将https改成AppStore的urlSchemes,即itms-apps
最后用打开openURL方法打开该链接即可。如下:
NSString *urlStr =@"itms-apps://itunes.apple.com/cn/app/tao-bao-sui-shi-sui-xiang/id387682726?mt=8";
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:urlStr]];
补充:手机iTunes Store的urlSchemes为itms,不要弄混。
还有另外一种跳转AppStore的链接,如下:
itms-apps://itunes.apple.com/app/id387682726?mt=8
只需要去ituns connect里面找到自己应用的AppId 进行替换即可即可。
从app跳转到AppStore方法:
- (void)gotoAppStore {
NSString * urlStr = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?mt=8",@"1205952707"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}
获取iOS当前版本号
//此获取的版本号对应bundle,打印出来对应为12345这样的数字
NSNumber *number = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
//此获取的版本号对应version,打印出来对应为1.2.3.4.5这样的字符串
NSString *string = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
获取app在AppStore上的版本号
- (void)getVersionForAppStore {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer =[AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"1205952707"];
[manager POST:urlStr parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *array = responseObject[@"results"];
NSDictionary *dic = array[0];
NSString *appStoreVersion = dic[@"version"];
NSLog(@"AppStore上当前app的版本号:%@",appStoreVersion);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@", error);
}];
}