iOS - Neosurance SDK v3.0.16
- 收集来自设备传感器和托管应用的信息
- 与人工智能引擎交换信息
- 发送推送通知
- 显示着陆页
- 显示已购买政策的列表
安装
iOS
-
要运行示例项目,请克隆仓库,然后先将文件 .podspec 中的版本更新为 "s.version = '3.0.15'",最后从 Example 目录运行
pod install
-
NeosuranceSDK(NSR) 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:
use_frameworks!
target 'NSR_Example' do
pod 'NSR_v3', :path => '../'
end
要求
-
在您的 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 方法内部)使用以下参数调用 设置 方法:
base_url:由我们提供,在没有配置 securityDelegate 的情况下使用
code:我们提供的社区代码
secret_key:我们提供的社区密钥
dev_mode 可选:[0|1] 激活 开发者模式
bar_style 可选:[UIStatusBarStyleDefault|UIStatusBarStyleLightContent] 在网页中指定状态栏样式(如果没有指定,则使用当前样式)
back_color 可选:[UIColor] 在网页中指定状态栏背景(如果没有指定,则使用当前背景)(文件 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>];
-
注册用户
当您的应用程序识别到用户时,使用 registerUser 方法在我们的 SDK 中注册用户,创建一个 NSRUser。
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];
-
显示应用
可以使用 showApp 方法显示已购买政策的列表(communityApp)
[[NSR sharedInstance] showApp];
或者
NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; [params setObject:@"profiles" forKey:@"page"]; [[NSR sharedInstance] showApp:params];
-
显示 URL 可选
如果需要自定义浏览器视图,可以使用 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 文件。