NSR 2.3.1

NSR 2.3.1

Alessandro InfurnaNeosuranceSchrodinger 维护。



NSR 2.3.1

  • Neosurance

iOS - Neosurance SDK (NSR)

  • 从设备传感器和托管应用收集信息
  • 与 AI 引擎交换信息
  • 发送推送通知
  • 显示落地页面
  • 显示已购买的保单列表

示例

要先运行示例项目,请克隆仓库,然后从 Example 目录中首先运行 pod install

安装

NeosuranceSDK(NSR) 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中即可。

pod 'NSR'

需求

  1. 在您内部的 info.plist 中,请确保拥有以下权限

    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>
    <key>NSCameraUsageDescription</key>
    <string>use camera...</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Always and when in use...</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Always...</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>When in use...</string>
    <key>NSMotionUsageDescription</key>
    <string>Motion...</string>
    <key>UIBackgroundModes</key>
    <array>
      <string>fetch</string>
      <string>location</string>
      <string>remote-notification</string>
    </array>
  2. 将以下音频文件 NSR_push.wav 添加到您的应用程序资源包

使用

  1. 设置

    在您的应用程序启动流程中较早的阶段(通常是您的应用程序的 application didFinishLaunchingWithOptions 方法内部)使用以下内容调用 setup 方法:

    base_url:由我们提供,仅在未配置 securityDelegate 的情况下使用
    code:我们提供的社区代码
    secret_key:我们提供的社区密钥
    dev_mode 可选:[0|1] 启动 开发者模式
    bar_style 可选:[UIStatusBarStyleDefault|UIStatusBarStyleLightContent] 在 webview 中指定状态栏样式(如果未指定,则使用当前样式)
    back_color 可选:[UIColor] 在 webview 中指定状态栏的背景颜色(如果未指定,则使用当前背景)

    NSMutableDictionary* settings = [[NSMutableDictionary alloc] init];
    [settings setObject:@"https://<provided base url>/" forKey:@"base_url"];
    [settings setObject:@"<provided code>" forKey:@"code"];
    [settings setObject:@"<provided secret_key>" forKey:@"secret_key"];
    [settings setObject:[NSNumber numberWithInt:UIStatusBarStyleDefault] forKey:@"bar_style"];
    [settings setObject:[UIColor colorWithRed:0.2 green:1 blue:1 alpha:1] forKey:@"back_color"];
    [[NSR sharedInstance] setup:settings];
  2. forwardNotification

    为了管理由 SDK 生成的推送,请将 forwardNotification 方法添加到您的应用程序通知处理程序中

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
    	if(![[NSR sharedInstance] forwardNotification:response]) {
    		... //handle your notification
    	}
    	completionHandler();
    }

    并请记住也要实现:

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler  {
    	completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
    }
  3. setSecurityDelegate 可选

    如果必须使用任何策略来确保通信安全。
    可以配置以下协议实现的 securityDelegate

    @protocol NSRSecurityDelegate <NSObject>
    -(void)secureRequest:(NSString* _Nullable)endpoint payload:(NSDictionary* _Nullable)payload headers:(NSDictionary* _Nullable)headers completionHandler:(void (^)(NSDictionary* responseObject, NSError *error))completionHandler;
    @end

    然后使用 setSecurityDelegate 方法

    [[NSR sharedInstance] setSecurityDelegate:[[<yourSecurityDelegate> alloc] init];
  4. 设置WorkFlow代理 可选

    如果在执行用户登录或支付时必须中断购买流程。
    必须配置实现以下接口的 workflowDelegate

    @protocol NSRWorkflowDelegate <NSObject>
    -(BOOL)executeLogin:(NSString*)url;
    -(NSDictionary*)executePayment:(NSDictionary*)payment url:(NSString*)url;
    -(void)confirmTransaction:(NSDictionary*)paymentInfo;
    @end

    然后使用 setWorkflowDelegate 方法。

    [[NSR sharedInstance] setWorkflowDelegate:[[<yourWorkflowDelegate> alloc] init];

    在执行登录或支付时,必须调用 loginExecutedpaymentExecuted 方法以恢复流程。

    [[NSR sharedInstance] loginExecuted:<theGivenUrl>];
    ...
    [[NSR sharedInstance] paymentExecuted:<paymentTransactionInfo> url:<theGivenUrl>];
  5. registerUser

    当您的应用识别到用户时,使用 registerUser 方法在我们的 SDK 中注册用户,创建一个 NSRUser
    NSRUser 具有以下字段:

    code:您系统中用户的代码(可以是电子邮件)
    email:电子邮件是真实的字段键
    firstname《可选》
    lastname《可选》
    mobile《可选》
    fiscalCode《可选》
    gender《可选》
    birthday《可选》
    address《可选》
    zipCode《可选》
    city《可选》
    stateProvince《可选》
    country《可选》
    extra《可选》: 将与我们一起分享
    locals《可选》: 不会在设备外部暴露

    NSRUser* user = [[NSRUser alloc] init];
    user.email = @"[email protected]";
    user.code = @"[email protected]";
    user.firstname = @"Jhon";
    user.lastname = @"Doe";
    [[NSR sharedInstance] registerUser:user];
  6. forgetUser《可选》

    如果要将用户注销传播到SDK,请使用 forgetUser 方法。
    请注意,如果没有用户,则不会进行跟踪。

    [[NSR sharedInstance] forgetUser];	
  7. showApp 《可选》

    可以使用 showApp 方法显示购买策略列表(communityApp)。

    [[NSR sharedInstance] showApp];	

    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setObject:@"profiles" forKey:@"page"];
    [[NSR sharedInstance] showApp:params];	
  8. showUrl 可选

    如果需要自定义网页视图,可以使用 showUrl 方法

    [[NSR sharedInstance] showUrl:url];	

    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setObject:@"true" forKey:@"profile"];
    [[NSR sharedInstance] showUrl:url params:params];	
  9. sendEvent 可选

    应用可以通过 sendEvent 方法向系统发送显式事件

    NSMutableDictionary* payload = [[NSMutableDictionary alloc] init];
    [payload setObject:latitude forKey:@"latitude"];
    [payload setObject:longitude forKey:@"longitude"];
    [[NSR sharedInstance] sendEvent:@"position" payload:payload];
  10. sendAction 可选

    应用可以通过 sendAction 方法向系统发送跟踪信息事件

    [[NSR sendAction] sendAction:@"read" policyCode:@"xxxx123xxxx" details:@"general condition read"];

作者

[email protected]

许可

NeosuranceSDK 在 MIT 许可下可用。更多详情请参阅 LICENSE 文件。