InMoment 2.7.0

InMoment 2.7.0

许可证 未知
发布最后发布2020 年 9 月

InMoment, Inc.David Hainish 维护。



InMoment 2.7.0

  • InMoment, Inc.

InMoment iOS SDK

CocoaPods CocoaPods Carthage compatible CocoaPods

InMoment 是一个简单的框架,它允许客户端开发者启动并与 InMoment 网络调查进行交互。

屏幕截图

presentsurvey_fl completionpoint_fl lastpage_fl

系统要求

  • Xcode 9.3Swift 4.1。如果使用较新或较旧的 Xcode 或 Swift 版本,包含此框架的应用可能无法正确构建。如果您需要针对 Swift 4.0.2,请使用我们的 1.2.1.x 版本之一。如果您需要针对 Swift 4.0,请使用我们的 1.2.0.x 版本之一。如果您需要针对 Swift 3.1,请使用我们的 1.1.x 版本之一。如果您需要针对 Swift 3.0,请使用我们的 1.0.x 版本之一。如果您需要针对 Swift 2.2,请使用我们的 0.4.x 版本之一。
  • 应用必须要求 iOS 8.0 或更高版本。

安装

推荐使用 CocoaPods

  1. 将适当的条目添加到应用程序的 Info.plist (请参阅“隐私”)。
  2. 将以下内容添加到您的 Podfile
use_frameworks!
pod 'InMoment'
  1. 运行 pod install

Carthage

  1. 将以下内容添加到您的 Cartfile
github 'InMoment/inmoment-sdk-ios'
  1. 运行 carthage bootstrapcarthage update
  2. 在您的应用目标的 General 设置选项卡上,将 InMoment.frameworkCarthage/Build 文件夹拖动到 Embedded binaries (嵌入式二进制文件)部分。
  3. 在您的应用目标的 Build Phases 设置选项卡上,单击 + 图标并选择 New Run Script Phase(新建运行脚本阶段)。创建一个运行脚本,指定您的shell(例如:bin/sh),并在shell下面添加以下内容到脚本区域
/usr/local/bin/carthage copy-frameworks

Input Files (输入文件)下添加以下行

$(SRCROOT)/Carthage/Build/iOS/InMoment.framework

此脚本旨在解决由通用二进制文件触发的 App Store 提交错误,确保在存档时复制必要的位码相关文件和符号文件。

  1. 别忘了将适当的条目添加到您的 Info.plist 中(请参阅“隐私”)。

手动安装

请参阅我们的手动安装指南

使用方法

为了使用此库,首先必须从您的 InMoment 客户成功经理(CSM)或技术成功经理(TSM)处获取有效的调查网关。以下部分提供了初始化 SDK 和显示调查的说明。还将讨论记录调查完成和错误处理的有用工具。

显示调查

调用以下 InMoment 类的方法将显示一个调查。

InMoment.presentSurvey(context: self, gateway: "MyGateway", parameters: ["Key":"Value"])

调用此方法将使用给定的 style 以模态方式显示调查。

  • context(必填):一个 UIViewController 的实例。此视图控制器将作为调查视图控制器的主机。
  • gateway(必填):有效的 InMoment 网络调查网关。请向您的 CSM 或 TSM 获取详细信息。
  • parameters(可选):与任何调查 URL 参数对应的字符串字典。
  • style(可选):一个类型为 SurveyStyle 的对象。

使用 SurveyListener

如果需要,SDK 可以使用 SurveyListener 的实例进行初始化。通常这是通过 AppDelegate 来完成的,但只要在调用 presentSurvey 之前进行,就可以在任何地方完成。

要初始化 SDK,请修改您的应用的 AppDelegate 如下:

import InMoment

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SurveyListener {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        InMoment.initialize(surveyListener: self)
        return true
    }

    func onReceivedError(_ survey: Survey, error: NSError) {
        //Insert your own code here. This method is optional.
    }

    func onArrivedAtLastPage(_ survey: Survey) {
        //Insert your own code here. This method is optional.
    }

    func onPassedCompletionPoint(_ survey: Survey) {
        //Insert your own code here. This method is optional.
    }

}

有用的工具

以下部分将讨论一些用于操作和从调查中提取信息的实用工具。

记录调查完成

有两种方式可以记录调查完成:用户通过调查的《完成点》,以及当用户到达调查的《最后一页》时。前者适用于确定调查响应何时被 InMoment 平台视为“完成”并将在报告中可用。后者更适用于确定没有其他调查页面存在,以及记录像调查的 兑换码 这样的信息。

超过完成点后

当用户到达调查完成点后的页面时,将调用此方法。一旦发生这种情况,调查结果将在 InMoment 报告和 Hub 2.0™ 中可用,(即使用户未继续到调查的最后页面)。在您的应用中的 SurveyListener 中实现此方法,以执行诸如记录用户已完成调查或向用户奖励的行为。

示例用法

func onPassedCompletionPoint(_ survey: Survey) {
    myUsersAwesomeRewardPoints.increment(by: 100)
}
在最后页面到达时

当用户到达调查的最后页面时,将调用此方法。在您的应用中的 SurveyListener 中实现此方法,以执行诸如记录兑换和最终关闭调查的操作。

示例用法

func onArrivedAtLastPage(_ survey: Survey) {
    var redemptionCode = survey.getRedemptionCode()
    myUsersSavedRedemptionCodes.save(code: redemptionCode)
    survey.createAlertDialog()
        .setTitle("Thank you!")
        .setMessage("Your feedback has been recorded")
        .addButton("OK", preferred: true, onClick: { survey.dismiss() })
        .show()
}

处理错误

在加载或进行调查期间发生错误时,将调用此方法。在您的应用中的 SurveyListener 中实现此方法,以执行诸如尝试重新启动调查或记录错误,并最终关闭调查的操作。

示例

func onReceivedError(_ survey: Survey, error: NSError) {
    NSLog(error.localizedDescription)
    NSLog(error.localizedFailureReason ?? "")
    NSLog(error.localizedRecoverySuggestion ?? "")
    survey.createAlertDialog()
        .setTitle("Oops!")
        .setMessage("Something went wrong!")
        .addButton("Try again", onClick: { survey.startOver() })
        .addButton("Cancel", style: .destructive, preferred: true, onClick: { survey.dismiss() })
        .show()
}

自定义调查的外观

SurveyStyle 实例传递给 InMoment.presentSurvey(),将使调查视图控制器中的导航栏和进度条应用所希望的样式效果。

public class SurveyStyle {
    public var modalPresentationStyle: UIModalPresentationStyle = .pageSheet
    public var navigationBarStyle: UIBarStyle = .default
    public var navigationBarTintColor: UIColor? = nil
    public var navigationBarTextColor: UIColor? = UIColor.darkText
    public var progressBarColor: UIColor? = InMomentGreenColor
    public var loadingViewStyle: LoadingViewStyle = .lightGray
}

隐私

如果一个调查有一个视频反馈提示,调查将尝试访问设备的相机、麦克风和/或照片库。SDK 在编译时不知道调查是否有视频反馈提示;因此,必须将以下条目添加到应用的 Info.plist

  • NSCameraUsageDescription(隐私 - 相机使用说明)
  • NSMicrophoneUsageDescription(隐私 - 麦克风使用说明)
  • NSPhotoLibraryUsageDescription(隐私 - 照片库使用说明)

未能将这些条目添加到应用的 Info.plist 将导致应用在被提交到 App Store 时被拒绝。