Delighted 1.4.1

Delighted 1.4.1

thierryErik PilzBen Turner维护。



Delighted 1.4.1

  • Delighted

Delighted iOS SDK

Delighted iOS SDK允许您在iOS应用中快速轻松地收集客户反馈。

需求

Delighted iOS SDK需要Xcode 10.2或更高版本,并且与针对iOS 12.1或更高版本的应用兼容。请注意,SDK是为iPhone的纵向模式设计的。目前不支持其他iOS设备的支持,特别是iPad。

Swift版本

  • Swift 4
  • Swift 4.2
  • Swift 5

依赖项

SDK需要一个依赖项Starscream以支持WebSocket。

安装

我们建议使用包管理器,如 CocoaPodsCarthageSwift Package Manager 来安装 Delighted iOS SDK。

CocoaPods

要使用 Delighted,请将以下 Podfile 添加到您的项目中。

source "https://github.com/CocoaPods/Specs.git"
platform :ios, "12.1"
use_frameworks!

pod "Delighted", "~> 1.4.0"

然后运行

pod install

Carthage

查看 Carthage 文档了解如何添加和安装。Delighted 框架已经配置好共享方案。

要在 Xcode 项目中集成 Delighted 并使用 Carthage,在您的 Cartfile 中指定它。

github "delighted/delighted-ios" >= 1.4.0

Swift Package Manager

使用此存储库的 URL(https://github.com/delighted/delighted-ios)通过 Xcode 项目添加一个包依赖项。

入门

当用户激活应用程序时初始化 SDK。初始化 SDK 后,您可以在任何想要展示调查的地方调用 survey(...)

在展示调查之前,我们会确认您的 Mobile SDK 平台已为您的项目启用,并检查此人是否最近接受过调查,以及其他事项。我们还自动管理调查的抽样,以确保您收到稳定的反馈流量,而不是在一天内处理完整个计划量。因此,调用 survey(...) 可能不会总是导致展示调查。

Swift

在您的AppDelegateapplicationDidBecomeActive(_:)方法中添加初始化代码。

import UIKit
import Delighted

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    return true
  }
    
  func applicationDidBecomeActive(_ application: UIApplication) {
    Delighted.initializeSDK()
  }
}

在您希望显示调查的地方调用Delighted.survey(...)。例如,当视图加载时触发调查,您可能做以下操作

import UIKit
import Delighted

class SomeViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx")
    }
}

Objective-C

Objective-C中的初始化与此类似。

#import "AppDelegate.h"
#import <Delighted/Delighted-Swift.h>

@interface AppDelegate ()
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [Delighted initializeSDK];
}

@end

在您希望显示调查的视图中,更新头文件中的视图控制器定义,使其引用DelightedDelegate

#import <UIKit/UIKit.h>
#import <Delighted/Delighted-Swift.h>

@interface ViewController : UIViewController<DelightedDelegate>

@end

然后更新实现在调用调查时调用onStatusWithError以处理回调。

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (IBAction)Survey:(id)sender {
    Delighted.delegate = self;
    [Delighted surveyWithDelightedID:@"mobile-sdk-xxxxxxxx"
                               token:nil
                              person:nil
                          properties:nil
                             options:nil
                eligibilityOverrides: [[EligibilityOverrides alloc] initWithTestMode:YES createdAt:nil]
                    inViewController:nil];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)onStatusWithError:(NSError * _Nullable)error surveyResponseStatus:(enum DelightedSurveyResponseStatus)surveyResponseStatus {
    NSLog(@"Survey complete");
}

@end

Delighted ID

当您的代码调用survey函数时,需要传递一个delightedID。您可以在https://delighted.com/integrations/mobile_sdk找到您的Delighted ID。Delighted ID被视为公开,可以像处理其他配置设置一样处理。

如果您有多个项目,每个项目都将有其独特的ID。这使您可以在应用程序中包含多个调查。

示例

唯一必需的参数是Delighted ID。

Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx")

通过传递一个Person,调查也可以与个人关联。

let person = Person(
    name: "Lauren Ipsum", 
    email: "[email protected]", 
    phoneNumber: "+14155551212"
)
Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", person: person)

与其他Delighted平台一样,您可以将属性与调查关联,以提供上下文并对响应进行分段。

var properties: Properties = [
    "customerId": "123",
    "location": "USA"
]
Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", properties: properties)

DELIGHTED的特殊属性可以用来进一步自定义调查体验。例如,要将调查改为德语显示,您可能使用如下代码

var properties: Properties = [
    "locale": "de"
]
Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", properties: properties)

在某些情况下,您可能需要覆盖用于决定是否显示调查的一些设置。最常见的将是开发时使用testMode来跳过所有检查并强制显示调查。

let eligibilityOverrides = EligibilityOverrides(
    testMode: true
)
Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", eligibilityOverrides: eligibilityOverrides)

initialDelay 可以传递以指定在向用户展示第一份调查前的等待秒数。这在您希望在用户使用您的应用一定时间后,用户才有资格接受调查的情况下非常有用。

let eligibilityOverrides = EligibilityOverrides(
    initialDelay: 86400
)
Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", eligibilityOverrides: eligibilityOverrides)

当首次调用 Delighted.initialize() 时,设备上会存储一个时间戳。《initialDelay》基于这个值。如果您想使用不同的起始延迟参考点,可以设置 createdAt

当您想要控制多久调查一次用户时,会用到 recurringPeriod

let eligibilityOverrides = EligibilityOverrides(
    createdAt: yourUserModel.createdAt,
    initialDelay: 86400,
    recurringPeriod: 1036800
)
Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", eligibilityOverrides: eligibilityOverrides)

处理状态和错误

在这些情况下,您可以传递一个回调来监控调查的状态或触发一个事件。

Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", callback: { (status) in
    switch status {
    case let .failedClientEligibility(status):
        // Maybe log this?
        // Do any view/screen changes that you need
    case let .error(status):
        // Maybe log this?
    case let .surveyClosed(status):
        // Re-register for keyboard notifications if unregistered
        // Do any view/screen changes that you need
    }
})

展示

Delighted SDK 提供了多种设置来控制调查的外观。

  • 可以更改每个组件的背景、边框和文字颜色。
  • 用户可以选择使用居中的模态框还是从屏幕底部弹出卡片来提示用户。
  • 按钮形状可以是圆形、方形或者带圆角的方形。
  • 按钮也可以是实心或轮廓。
  • 您可以控制“感谢”页面是否保持在打开状态直到用户明确关闭它,或者在一定时间后自动关闭(默认为两秒后关闭)。
  • iOS 键盘可以设置为浅色模式、深色模式或使用系统默认。
  • 状态栏(显示时钟和运营商信息的地方)可以隐藏或显示。
  • 可以覆盖字体。
  • 如果需要,甚至可以覆盖文本标签。

最常用的设置可以通过浏览到 Mobile SDK 的 自定义外观 页面来更新。如果您想更改其他设置,请与 Delighted 的 客户服务 团队联系。

另外,您也可以通过自己的代码控制调查的外观。您提供的值将优于您 Delighted 项目的配置。如果您选择通过代码描述设置,则需要提供所有主题设置的值。我们鼓励您与 Delighted 的 客户服务 团队联系,以便帮助您评估权衡并为您应用程序做出最佳选择。

let options = Options(
    nextText: "Next 👉",
    prevText: "👈 Previous",
    selectOneText: "Select one",
    selectManyText: "Select many",
    submitText: "Submit 👌",
    doneText: "Done ✅",
    notLikelyText: "Not likely",
    veryLikelyText: "Very likely",
    theme: Theme(
        display: .card,
        containerCornerRadius: 20.0,
        primaryColor: LocalThemeColors.primaryColor,
        buttonStyle: .outline,
        buttonShape: .roundRect,
        backgroundColor: LocalThemeColors.grayDarkest,
        primaryTextColor: LocalThemeColors.white,
        secondaryTextColor: LocalThemeColors.white,
        textarea: Theme.TextArea(
            backgroundColor: LocalThemeColors.grayDark,
            textColor: LocalThemeColors.white,
            borderColor: LocalThemeColors.grayDark),
        primaryButton: Theme.PrimaryButton(
            backgroundColor: LocalThemeColors.primaryColor,
            textColor: LocalThemeColors.grayDarkest,
            borderColor: LocalThemeColors.primaryColor),
        secondaryButton: Theme.SecondaryButton(
            backgroundColor: LocalThemeColors.grayDarkest,
            textColor: LocalThemeColors.primaryColor,
            borderColor: LocalThemeColors.primaryColor),
        button: Theme.Button(
            activeBackgroundColor: LocalThemeColors.primaryColor,
            activeTextColor: LocalThemeColors.grayDarkest,
            activeBorderColor: LocalThemeColors.primaryColor,
            inactiveBackgroundColor: LocalThemeColors.grayDarkest,
            inactiveTextColor: LocalThemeColors.primaryColor,
            inactiveBorderColor: LocalThemeColors.primaryColor),
        stars: Theme.Stars(
            activeBackgroundColor: LocalThemeColors.primaryColor,
            inactiveBackgroundColor: LocalThemeColors.gray),
        icon: Theme.Icon(
            activeBackgroundColor: LocalThemeColors.primaryColor,
            inactiveBackgroundColor: LocalThemeColors.gray),
        scale: Theme.Scale(
            activeBackgroundColor: LocalThemeColors.primaryColor,
            activeTextColor: LocalThemeColors.grayDarkest,
            activeBorderColor: LocalThemeColors.primaryColor,
            inactiveBackgroundColor: LocalThemeColors.grayDarkest,
            inactiveTextColor: LocalThemeColors.primaryColor,
            inactiveBorderColor: LocalThemeColors.primaryColor),
        slider: Theme.Slider(
            knobBackgroundColor: LocalThemeColors.primaryColor,
            knobTextColor: LocalThemeColors.white,
            knobBorderColor: LocalThemeColors.primaryColor,
            trackActiveColor: LocalThemeColors.primaryColor,
            trackInactiveColor: LocalThemeColors.white,
            hoverBackgroundColor: LocalThemeColors.grayDarkest,
            hoverTextColor: LocalThemeColors.primaryColor,
            hoverBorderColor: LocalThemeColors.primaryColor),
        closeButton: Theme.CloseButton(
            normalBackgroundColor: LocalThemeColors.gray,
            normalTextColor: LocalThemeColors.grayDark,
            normalBorderColor: LocalThemeColors.gray,
            highlightedBackgroundColor: LocalThemeColors.gray,
            highlightedTextColor: LocalThemeColors.grayDarker,
            highlightedBorderColor: LocalThemeColors.gray),
        ios: Theme.IOS(keyboardAppearance: .dark,
            statusBarMode: .lightContent,
            statusBarHidden: false)
    ),
    fontFamilyName: "MarkerFelt-Wide",
    thankYouAutoCloseDelay: 10
)

Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", options: options)

故障排除

您可以将日志级别更改为向控制台打印详细信息。

Delighted.logLevel = .debug

回调也可以用来获取更多信息并探索行为。

Delighted.survey(delightedID: "mobile-sdk-xxxxxxxxx", callback: { (status) in
  switch status {
  case let .failedClientEligibility(status):
    print("Eligibility check failed")     
  case let .error(status):
    print("An error occurred")     
  case let .surveyClosed(status):
    print("Survey closed")     
  }
})

计费

类似于Delighted的Web平台,SDK根据向您展示调查的人数来计费。当您的账户超出其计划限制时,调查将不会在iOS应用中显示,直到下一个计费周期或您切换到一个更高限制的计划。

支持

请与Delighted Concierge团队联系,解答疑问或报告问题。

示例应用

SDK中包含的示例应用程序展示了每种类型调查的示例以及一些常见使用情况。这是一个使用Delighted的Demo作为问题来源的完整工作应用。

设置说明

  1. 克隆/分叉此存储库
  2. 使用bundle install安装Fastlane和CocoaPods
  3. 运行cd Example,然后pod install
  4. 在Xcode中打开Example/delighted.xcworkspace

构建后,启动iOS模拟器。

测试

这些测试位于 Example 应用中,可以通过以下方式运行:

  1. 运行 fastlane ios test
  2. 打开 Example/delighted.xcworkspace 并运行测试