美文网首页iOS UI开发
iOS应用内评价 快速打开撰写评价页面

iOS应用内评价 快速打开撰写评价页面

作者: reviewThis | 来源:发表于2018-10-02 10:50 被阅读184次

    应用内打开app 在AppStore详情页

    • 导入#import <StoreKit/StoreKit.h>
    • 实现代理SKStoreProductViewControllerDelegate

    创建并打开页面

    - (void)showAppStoreReviewId:(NSString *)appId
    {
        SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc]init];
        storeProductVC.delegate = self;
        NSDictionary *dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier];
        [storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError * _Nullable error) {
            if (!error) {
                [self presentViewController:storeProductVC animated:YES completion:nil];
            }
        }];
    }
    
    //点击了完成按钮
    - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
    {
        NSLog(@" 评价完成");
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    

    应用内评价

    - (void)addAppReviewWithAppId:(NSString *)appId{
        UIAlertController * alertVC = [UIAlertController alertControllerWithTitle:@"亲喜欢**APP么?给个五星好评吧!" message:nil preferredStyle:UIAlertControllerStyleAlert];
        //跳转APPStore 中应用的撰写评价页面
        UIAlertAction *review = [UIAlertAction actionWithTitle:@"我要吐槽" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSURL *appReviewUrl = [NSURL URLWithString:[NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",appId]];
            CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
            if (version >= 10.0) {
                [[UIApplication sharedApplication] openURL:appReviewUrl options:@{} completionHandler:nil];
            }else{
                [[UIApplication sharedApplication] openURL:appReviewUrl];
            }
        }];
        //不做任何操作
        UIAlertAction *noReview = [UIAlertAction actionWithTitle:@"用用再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [alertVC removeFromParentViewController];
        }];
        
        [alertVC addAction:review];
        [alertVC addAction:noReview];
        //判断系统,是否添加五星好评的入口
        if (@available(iOS 10.3, *)) {
            if([SKStoreReviewController respondsToSelector:@selector(requestReview)]){
                UIAlertAction *fiveStar = [UIAlertAction actionWithTitle:@"五星好评" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [[UIApplication sharedApplication].keyWindow endEditing:YES];
                    //  五星好评
                    [SKStoreReviewController requestReview];
                }];
                [alertVC addAction:fiveStar];
            }
        } else {
            // Fallback on earlier versions
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [[[[UIApplication sharedApplication]keyWindow] rootViewController] presentViewController:alertVC animated:YES completion:nil];
        });
    }
    

    应用内直接跳转到AppStore应用详情页、撰写评论页

    • 应用详情页
    - (void)jumpToAppStroeDetialPageWithAppId:(NSString *)appId {
        NSString *appUrl = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8",appId];
        if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:appUrl]]) {
            if (iOS_10_System_Later) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl] options:@{} completionHandler:nil];
            } else {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl]];
            }
        }
    }
    
    • 撰写评论页
    - (void)jumpToAppStroeSortOrderPageWithAppId:(NSString *)appId {
        NSString *appUrl = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review",appId];
        if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:appUrl]]) {
            if (iOS_10_System_Later) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl] options:@{} completionHandler:nil];
            } else {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:appUrl]];
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS应用内评价 快速打开撰写评价页面

        本文链接:https://www.haomeiwen.com/subject/dnmvoftx.html