iOS小技能:app信息查询(应用内调转到app store进行评论)

908 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第9天,点击查看活动详情

前言

应用内调转到app store进行评论:itms-apps://itunes.apple.com/app/idxxxxx?action=write-review

搜索接口:https://itunes.apple.com/search?term=xx&country=cn&limit=200&entity=software

APP 详细信息接口可用于检查版本: https://itunes.apple.com/cn/lookup?id=

APP 评论内容:https://itunes.apple.com/cn/rss/customerreviews/id=/sortBy=mostRecent/json

I app信息查询

1.1 应用分享

UIActivityViewController

        NSURL *shareUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",@"itms-apps://itunes.apple.com/app/id",APPID]];
        UIImage *shareImage = [UIImage imageNamed:@"green-unselected"];
        NSString *shareText = NSLocalizedString(@"应用分享", nil);
        NSArray *items = @[shareText,shareImage,shareUrl];
        UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];

1.2 应用内调转到app store进行评论

showRateAlert

Rate it now

#define kAppStoreAddress @"itms-apps://itunes.apple.com/app/id162?action=write-review"

                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:kAppStoreAddress]];

  • 评价应用
        NSString *openAppStore = [NSString  stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",APPID];//替换为对应的APPID
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openAppStore]];

1.3 检查版本

  1. 按照位数进行依次比对,而不是去掉.分隔符再比较大小 blog.csdn.net/z929118967/…

  2. 去掉.分隔符比较大小【不推荐】

比如3.1.0 和3.0.16 如果是先去掉.分隔符再比较大小,这样会导致误判,因为3016 比3.1.0更大。 除非提前规定约定好,版本号至少固定4位,或者五位。 即 3.1.00 和3.0.16 . 但是这样容易因为人的疏忽而导致判断失误。


#pragma mark 检查版本
- (void)checkTheVersionWithappid:(NSString*)appid{


    [QCTNetworkHelper getWithUrl:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",appid] params:nil successBlock:^(NSDictionary *result) {
        if ([[result objectForKey:@"results"] isKindOfClass:[NSArray class]]) {
            NSArray *tempArr = [result objectForKey:@"results"];
            if (tempArr.count) {
                
                
                NSString *versionStr =[[tempArr objectAtIndex:0] valueForKey:@"version"];
                NSString *appStoreVersion = [versionStr stringByReplacingOccurrencesOfString:@"." withString:@""] ;
                if (appStoreVersion.length==2) {
                    appStoreVersion  = [appStoreVersion stringByAppendingString:@"0"];
                }else if (appStoreVersion.length==1){
                    appStoreVersion  = [appStoreVersion stringByAppendingString:@"00"];
                }

                NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
                NSString* currentVersion = [[infoDic valueForKey:@"CFBundleShortVersionString"] stringByReplacingOccurrencesOfString:@"." withString:@""];
                
                currentVersion = [currentVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
                if (currentVersion.length==2) {
                    currentVersion  = [currentVersion stringByAppendingString:@"0"];
                }else if (currentVersion.length==1){
                    currentVersion  = [currentVersion stringByAppendingString:@"00"];
                }

                
                
                NSLog(@"currentVersion: %@",currentVersion);
                
                if([appStoreVersion floatValue] > [currentVersion floatValue]){
                    
                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"发现新版本%@",versionStr] message:@"是否更新?" preferredStyle:UIAlertControllerStyleAlert];
                    
                    [alertController addAction:[UIAlertAction actionWithTitle:@"稍后再说" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                        NSLog(@"取消更新");
                    }]];
                    [alertController addAction:[UIAlertAction actionWithTitle:@"立即去更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",appid]];
                        if (@available(iOS 10.0, *)) {
                            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
                            }];
                        } else {
                            // Fallback on earlier vesions
                            [[UIApplication sharedApplication] openURL:url];
                        }
                    }]];
                    [[QCT_Common getCurrentVC] presentViewController:alertController animated:YES completion:nil];
                }
            }
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"检查版本错误: %@",error);
    }];
}


see also

iOS小技能:拨号、发邮件、短信、应用间跳转 blog.csdn.net/z929118967/…