iOS - Neosurance SDK v4 1.0.4
- 收集来自设备和托管应用的设备传感器信息
- 与 AI 引擎交换信息
- 发送推送通知
- 显示落地页面
- 显示购买政策列表
安装
-
要运行示例项目,请克隆仓库,并首先从 Example 目录中运行
pod install
-
NeosuranceSDK (NSR) 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'NSR'
要求
-
在您的 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>
-
将以下音频文件 NSR_push.wav 添加到您的应用资源包中
设置
-
设置
在您应用启动流程的早期(通常在您的应用的 application didFinishLaunchingWithOptions 方法中)使用以下方式调用 setup 方法:
base_url:由我们提供,只在未配置 securityDelegate 时使用
code:由我们提供的社区代码
secret_key:由我们提供的社区密钥
dev_mode 可选:[0|1] 激活 开发者模式
bar_style 可选:[UIStatusBarStyleDefault|UIStatusBarStyleLightContent] 在webview中指定状态栏风格(如果没有指定,将使用当前样式)
back_color 可选:[UIColor] 在webview中指定状态栏背景(如果没有指定,将使用当前背景)(文件 config.plist)
<dict> <key>base_url</key> <string>https://...</string> <key>code</key> <string>code_string</string> <key>secret_key</key> <string>secret_key_string</string> <key>user.email</key> <string>[email protected]</string> <key>user.code</key> <string>[email protected]</string> <key>user.firstname</key> <string>Mario</string> <key>user.lastname</key> <string>Rossi</string> <key>user.fiscalCode</key> <string>RSSMRA85T01F205P</string> <key>user.stateProvince</key> <string>MI</string> <key>user.city</key> <string>Milano</string> <key>user.address</key> <string>Via Canova 12</string> <key>user.zipCode</key> <string>20127</string> <key>user.country</key> <string>Italia</string> <key>user.gender</key> <string>M</string> <key>user.birthday</key> <string>01-12-1985</string> <key>user.mobile</key> <string>3409876234</string> <key>user.extra</key> <string>nil</string> </dict>
[[NSR sharedInstance] setWorkflowDelegate:[[NSRSampleWFDelegate alloc] init]]; NSMutableDictionary* settings = [[NSMutableDictionary alloc] init]; [settings setObject:self.config[@"base_url"] forKey:@"base_url"]; [settings setObject:self.config[@"code"] forKey:@"code"]; [settings setObject:self.config[@"secret_key"] forKey:@"secret_key"]; [settings setObject:[NSNumber numberWithBool:YES] forKey:@"dev_mode"]; [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];
-
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); }
-
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];
-
setWorkFlowDelegate 可选
如果必须中断购买流程以执行用户登录或支付。
必须配置实现以下接口的 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];
在执行登录或支付时,必须调用 loginExecuted 和 paymentExecuted 方法来恢复工作流程
[[NSR sharedInstance] loginExecuted:<theGivenUrl>]; ... [[NSR sharedInstance] paymentExecuted:<paymentTransactionInfo> url:<theGivenUrl>];
-
注册用户
当用户被应用程序识别时,请使用我们的 SDK 进行注册,创建一个 NSRUser 对象,并使用 registerUser 方法。
NSRUser 包含以下字段:code:您系统中的用户代码(可以等于电子邮件地址)
email:电子邮件是真正的主键
firstname ——(可选)
lastname ——(可选)
mobile ——(可选)
fiscalCode ——(可选)
gender ——(可选)
birthday ——(可选)
address ——(可选)
zipCode ——(可选)
city ——(可选)
stateProvince ——(可选)
country ——(可选)
extra ——(可选):将与我们共享
locals ——(可选):不会暴露在设备之外(文件 config.plist)
<dict> <key>base_url</key> <string>https://...</string> <key>code</key> <string>code_string</string> <key>secret_key</key> <string>secret_key_string</string> <key>user.email</key> <string>[email protected]</string> <key>user.code</key> <string>[email protected]</string> <key>user.firstname</key> <string>Mario</string> <key>user.lastname</key> <string>Rossi</string> <key>user.fiscalCode</key> <string>RSSMRA85T01F205P</string> <key>user.stateProvince</key> <string>MI</string> <key>user.city</key> <string>Milano</string> <key>user.address</key> <string>Via Canova 12</string> <key>user.zipCode</key> <string>20127</string> <key>user.country</key> <string>Italia</string> <key>user.gender</key> <string>M</string> <key>user.birthday</key> <string>01-12-1985</string> <key>user.mobile</key> <string>3409876234</string> <key>user.extra</key> <string>nil</string> </dict>
NSRUser* user = [[NSRUser alloc] init]; user.code = self.config[@"user.code"]; user.email = self.config[@"user.email"]; user.firstname = self.config[@"user.firstname"]; user.lastname = self.config[@"user.lastname"]; user.country = self.config[@"user.country"]; user.fiscalCode = self.config[@"user.fiscalCode"]; user.address = self.config[@"user.address"]; user.city = self.config[@"user.city"]; user.stateProvince = self.config[@"user.stateProvince"]; //user.mobile = self.config[@"user.mobile"]; //user.gender = self.config[@"user.gender"]; //user.birthday = self.config[@"user.birthday"]; //user.zipCode = self.config[@"user.zipCode"]; NSDictionary* locals = [[NSMutableDictionary alloc]init]; [locals setValue:user.email forKey:@"email"]; [locals setValue:user.firstname forKey:@"firstname"]; [locals setValue:user.lastname forKey:@"lastname"]; [locals setValue:user.fiscalCode forKey:@"fiscalCode"]; [locals setValue:user.address forKey:@"address"]; [locals setValue:user.city forKey:@"city"]; [locals setValue:user.stateProvince forKey:@"stateProvince"]; [locals setValue:@"fake-push" forKey:@"pushToken"]; [user setLocals: locals]; [[NSR sharedInstance] registerUser:user];
-
forgetUser ——(可选)
如果想要通过 SDK 将用户登出传播,请使用 forgetUser 方法。
注意,如果没有用户,则不会进行跟踪。[[NSR sharedInstance] forgetUser];
-
显示应用
可以使用 showApp 方法显示购买的政策列表(如 communityApp)。
[[NSR sharedInstance] showApp];
或者
NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; [params setObject:@"profiles" forKey:@"page"]; [[NSR sharedInstance] showApp:params];
-
showUrl ——(可选)
如果需要自定义网络视图,则可以使用 showUrl 方法。
[[NSR sharedInstance] showUrl:url];
或者
NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; [params setObject:@"true" forKey:@"profile"]; [[NSR sharedInstance] showUrl:url params:params];
-
发送事件
应用程序可以使用 sendEvent 方法向系统发送显式事件。
NSMutableDictionary* payload = [[NSMutableDictionary alloc] init]; [payload setObject:latitude forKey:@"latitude"]; [payload setObject:longitude forKey:@"longitude"]; [[NSR sharedInstance] sendEvent:@"position" payload:payload];
-
sendAction ——(可选)
应用程序可以使用 sendAction 方法向系统发送跟踪信息事件。
[[NSR sendAction] sendAction:@"read" policyCode:@"xxxx123xxxx" details:@"general condition read"];
用法(示例演示流程)
- 点击按钮 => "设置"(见1. 设置)
- 点击按钮 => "registerUser"(见5. registerUser)
- [4.] 点击按钮 => "sendEvent_1"(和/或 "sendEvent_2",和/或 "sendEventPush" 和/或 "sendEventPush_2")(见9. sendEvent)
- [3.] 点击按钮 => "showApp"为显示“购买清单”或“购买新的保险政策”(只需点击标题即可)(见7. showApp)
作者
许可证
NeosuranceSDK可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。