项目经验iOSiOS 实用

iOS集成阿里百川用户反馈功能及给app评分

2016-07-11  本文已影响6244人  若锦

用户反馈功能几乎是每个app都有的一个功能点,通过反馈功能实现与用户的连接、沟通,随时随地收集用户意见反馈和Bug报告,即时和用户保持沟通,在一定程度上提升了app的竞争力。而给app评分也是一个常见的功能。接下来和大家分享如何在自己的工程中集入阿里百川的用户反馈模块,另外介绍如何实现对app的评分功能。

一、用户反馈功能
1.首先需要到阿里百川申请appkey.同时生成自己需要的SDK并下载下来,将SDK导入到自己的工程中,另外将阿里百川的demo下载下来,把里面的TWMessageBarManager包也导入自己的工程中。

2.在工程中添加以下的依赖库:

UIKit.framework
AddressBook.framework
SystemConfiguration.framework
CoreLocation.framework
CoreTelephony.framework
CoreData.framework
libz.tbd
libstdc++.6.0.9.tbd
MobileCoreServices.framework
ImageIO.framework
AudioToolbox.framework
AVFoundation.framework
AssetsLibrary.framework
CoreMotion.framework

3.导入头文件

#import <YWFeedbackFMWK/YWFeedbackKit.h>
#import "TWMessageBarManager.h"

4.实现反馈功能

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"意见反馈与给app评分";
    self.view.backgroundColor = [UIColor whiteColor];
//    在阿里百川申请的appkey
    self.appKey = @"appkey";
    self.environment = YWEnvironmentRelease;
    
    UIButton *feedbackButton = [UIButton buttonWithType:UIButtonTypeSystem];
    feedbackButton.frame = CGRectMake(100, 150, 100, 50);
    [self.view addSubview:feedbackButton];
    [feedbackButton setTitle:@"意见反馈" forState:UIControlStateNormal];
    [feedbackButton addTarget:self action:@selector(actionOpenFeedback) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *markButton = [UIButton buttonWithType:UIButtonTypeSystem];
    markButton .frame = CGRectMake(100, 200, 100, 50);
    [self.view addSubview:markButton];
    [markButton setTitle:@"评分" forState:UIControlStateNormal];
    [markButton addTarget:self action:@selector(markButtonAction) forControlEvents:UIControlEventTouchUpInside];
    // Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -- 调起意见反馈
- (void )actionOpenFeedback{
    self.tabBarController.tabBar.hidden = YES;
    
    self.appKey = @"appkey";
    
    self.feedbackKit = [[YWFeedbackKit alloc] initWithAppKey:self.appKey];
    
    _feedbackKit.environment = self.environment;
    
#warning 设置App自定义扩展反馈数据
    _feedbackKit.extInfo = @{@"loginTime":[[NSDate date] description],
                             @"visitPath":@"登陆->关于->反馈",
                             @"应用自定义扩展信息":@"开发者可以根据需要设置不同的自定义信息,方便在反馈系统中查看"};
#warning 自定义反馈页面配置
    _feedbackKit.customUIPlist = [NSDictionary dictionaryWithObjectsAndKeys:@"/te\'st\\Value1\"", @"testKey1", @"test<script>alert(\"error.yaochen\")</alert>Value2", @"testKey2", nil];
    
    [self _openFeedbackViewController];
}


#pragma mark 弹出反馈页面
- (void)_openFeedbackViewController
{
    __weak typeof(self) weakSelf = self;
    
    [_feedbackKit makeFeedbackViewControllerWithCompletionBlock:^(YWFeedbackViewController *viewController, NSError *error) {
        if ( viewController != nil ) {
#warning 这里可以设置你需要显示的标题以及nav的leftBarButtonItem,rightBarButtonItem
            viewController.title = @"意见反馈";
            //
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
            
            viewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1],NSFontAttributeName : [UIFont fontWithName:@"Helvetica" size:18]};
            [self.navigationController pushViewController:viewController animated:YES];
            
            viewController.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
            self.navigationController.interactivePopGestureRecognizer.delegate=(id)self;
            viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:weakSelf action:@selector(cancelButtonAction)];
            viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:0.59 green:0.59 blue:0.59 alpha:1];
            viewController.tabBarController.tabBar.hidden = YES;
            
            
            __weak typeof(nav) weakNav = nav;
            
            [viewController setOpenURLBlock:^(NSString *aURLString, UIViewController *aParentController) {
                UIViewController *webVC = [[UIViewController alloc] initWithNibName:nil bundle:nil];
                UIWebView *webView = [[UIWebView alloc] initWithFrame:webVC.view.bounds];
                webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
                
                [webVC.view addSubview:webView];
                [weakNav pushViewController:webVC animated:YES];
                [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:aURLString]]];
            }];
        } else {
            NSString *title = [error.userInfo objectForKey:@"msg"]?:@"接口调用失败,请保持网络通畅!";
            
            [[TWMessageBarManager sharedInstance] showMessageWithTitle:title description:nil
                                                                  type:TWMessageBarMessageTypeError];
        }
    }];
}

-(void)cancelButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}

二、给app评分有两种方式,一种是跳转到AppStore中评分,另外一种是利用StoreKit在应用内实现评分,但是第二方法种有点慢。

1.直接跳转到AppStore

// 跳转到AppStore评分,xxxxxx是app的ID,可在AppStore上查看链接获取URL
   NSString *baseUrl = @"https://itunes.apple.com/cn/app/jing-dai/idxxxxxx?mt=8" ;
   [[UIApplication sharedApplication]openURL:[NSURL URLWithString:baseUrl]];

2.利用StoreKit在应用内实现评分
首先导入#import <StoreKit/StoreKit.h>
签代理SKStoreProductViewControllerDelegate
实现方法

//  应用内给app评分,可返回之前的页面
    SKStoreProductViewController *storeProductVC =[[SKStoreProductViewController alloc]init];
    
        storeProductVC.delegate = self;
    
        //第一个参数为应用标识id构成的字典。第二个参数是一个block回调。
    
        [storeProductVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: @"1053328148" } completionBlock:^(BOOL result, NSError *error) {
    
            if (result) {

                [self presentViewController:storeProductVC animated:YES completion:^{
    
                }];
   
            }else{
    
                NSLog(@"错误:%@" ,error);
    
            }
    
        }];

实现代理方法

//SKStoreProductViewController代理方法

-(void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController

{
    
    //返回上一个页面
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


这样,意见反馈和评分的功能就实现了,很简单。用户发送意见反馈时,我们可以直接到阿里百川的后台给用户进行回复。
意见反馈效果图如下:

意见反馈

demo地址

上一篇下一篇

猜你喜欢

热点阅读