iOS集成阿里百川用戶反饋功能及給app評分

用戶反饋功能幾乎是每個app都有的一個功能點,通過反饋功能實現(xiàn)與用戶的連接、溝通,隨時隨地收集用戶意見反饋和Bug報告,即時和用戶保持溝通,在一定程度上提升了app的競爭力。而給app評分也是一個常見的功能。接下來和大家分享如何在自己的工程中集入阿里百川的用戶反饋模塊,另外介紹如何實現(xiàn)對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.實現(xiàn)反饋功能

- (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 -- 調(diào)起意見反饋
- (void )actionOpenFeedback{
    self.tabBarController.tabBar.hidden = YES;
    
    self.appKey = @"appkey";
    
    self.feedbackKit = [[YWFeedbackKit alloc] initWithAppKey:self.appKey];
    
    _feedbackKit.environment = self.environment;
    
#warning 設(shè)置App自定義擴展反饋數(shù)據(jù)
    _feedbackKit.extInfo = @{@"loginTime":[[NSDate date] description],
                             @"visitPath":@"登陸->關(guān)于->反饋",
                             @"應用自定義擴展信息":@"開發(fā)者可以根據(jù)需要設(shè)置不同的自定義信息,方便在反饋系統(tǒng)中查看"};
#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 這里可以設(shè)置你需要顯示的標題以及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"]?:@"接口調(diào)用失敗,請保持網(wǎng)絡通暢!";
            
            [[TWMessageBarManager sharedInstance] showMessageWithTitle:title description:nil
                                                                  type:TWMessageBarMessageTypeError];
        }
    }];
}

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

二、給app評分有兩種方式,一種是跳轉(zhuǎn)到AppStore中評分,另外一種是利用StoreKit在應用內(nèi)實現(xiàn)評分,但是第二方法種有點慢。

1.直接跳轉(zhuǎn)到AppStore

// 跳轉(zhuǎn)到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在應用內(nèi)實現(xiàn)評分
首先導入#import <StoreKit/StoreKit.h>
簽代理SKStoreProductViewControllerDelegate
實現(xiàn)方法

//  應用內(nèi)給app評分,可返回之前的頁面
    SKStoreProductViewController *storeProductVC =[[SKStoreProductViewController alloc]init];
    
        storeProductVC.delegate = self;
    
        //第一個參數(shù)為應用標識id構(gòu)成的字典。第二個參數(shù)是一個block回調(diào)。
    
        [storeProductVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: @"1053328148" } completionBlock:^(BOOL result, NSError *error) {
    
            if (result) {

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

實現(xiàn)代理方法

//SKStoreProductViewController代理方法

-(void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController

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


這樣,意見反饋和評分的功能就實現(xiàn)了,很簡單。用戶發(fā)送意見反饋時,我們可以直接到阿里百川的后臺給用戶進行回復。
意見反饋效果圖如下:

意見反饋

demo地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,366評論 25 708
  • 《登幽州臺歌》 前不見古人, 后不見來者。 念天地之悠悠, 獨悵然而涕下。 我小時讀它,并不能真正理解作者表達了一...
    維綺微雨閱讀 722評論 6 4
  • 那是上大學的第一個元旦,放假了,我們404宿舍的弟兄們都不回家。記不清宿舍里哪位提議,晚上包餃子,竟一致贊同,...
    老海李亞強閱讀 630評論 10 6
  • 打卡,第三天
    心無雜念yj閱讀 198評論 0 0
  • 1今天點開朋友圈,一個學妹說她二戰(zhàn)臨考了,頭上綁個毛巾,嘴里叼根筆,各種求點贊,求支持,說要開啟學霸模式。我果斷點...
    流光漣影閱讀 1,683評論 34 46

友情鏈接更多精彩內(nèi)容