多语言展示
当前在线:302今日阅读:103今日分享:49

OpeninstallSDK详细集成

OpeninstallSDK是一个轻量级推广神器,这里就介绍一下iOS的集成方法。
工具/原料
1

X-Code

2

OpeninstallSDK

方法/步骤
1

进入官网,点击进入 下载中心,选择iOS端对应的SDK点击下载。

2

将下载好的OpeninstallSDK文件夹直接拖入工程。

3

将下列代码复制到AppDelegate.m文件中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //初始化OpenInstall    [OpenInstallSDK setAppKey:@'orx4hy'  withDelegate:self];    return YES;} //通过OpenInstall 获取自定义参数。- (void)getInstallParamsFromOpenInstall:(NSDictionary *) params withError: (NSError *) error {    if (!error) {        NSLog(@'OpenInstall 自定义数据:%@', [params description]);                 if (params) {            NSString *paramsStr = [NSString stringWithFormat:@'%@',params];            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@'安装参数' message:paramsStr preferredStyle:  UIAlertControllerStyleAlert];            [alert addAction:[UIAlertAction actionWithTitle:@'确定' style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {            }]];                         //弹出提示框(便于调试,调试完成后删除此代码)            [self.window.rootViewController presentViewController:alert animated:true completion:nil];            //获取到参数后可保存到本地,等到需要使用时再从本地获取。            NSUserDefaults *openinstallData = [NSUserDefaults standardUserDefaults];             [openinstallData setObject:params forKey:@'openinstallParams'];                     }                      } else {        NSLog(@'OpenInstall error %@', error);    }}//已经安装app 被唤醒时获取参数(如果是通过渠道页面唤醒app时,会返回渠道编号),c 为渠道编号,d为渠道自定义参数- (void)getWakeUpParamsFromOpenInstall: (NSDictionary *) params withError: (NSError *) error {    NSLog(@'OpenInstall 唤醒参数:%@',params );    if(params ){        if (params) {            NSString *paramsStr = [NSString stringWithFormat:@'%@',params];            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@'唤醒参数' message:paramsStr preferredStyle:  UIAlertControllerStyleAlert];            [alert addAction:[UIAlertAction actionWithTitle:@'确定' style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}]];            //弹出提示框(便于调试,调试完成后删除此代码)            [self.window.rootViewController presentViewController:alert animated:true completion:nil];        }    }}//Universal Links 通用链接实现深度链接技术- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{    //判断是否通过OpenInstall Universal Links 唤起App    if ([OpenInstallSDK continueUserActivity:userActivity]){        return YES;    }else{        //其他代码;        return YES;}}//ios9以下 URL Scheme-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{        //判断是否通过OpenInstall URL Scheme 唤起App    if ([[url description] rangeOfString:@'openlink.cc'].location != NSNotFound) {                return   [OpenInstallSDK handLinkURL:url];    }else{        //自行处理;        return YES;    }        }//iOS9以上 URL Scheme- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(nonnull NSDictionary *)options{        //判断是否通过OpenInstall URL Scheme 唤起App    if ([[url description] rangeOfString:@'openlink.cc'].location != NSNotFound) {                return   [OpenInstallSDK handLinkURL:url];    }else{        //自行处理;        return YES;    }}

4

配置Universal Links:a)选中工程,在 TARGETS 中选择项目,点击 Capabilities 选项,找到 Associated Domains,展开Associated Domains 并打开右边对应的开关,点击 “+” 号,输入 “applinks:cf46vg.openlink.cc” (注意:其中的“cf46vg”要替换成你的应用在openinstall中注册的Appkey)b)到苹果开发者网站,为当前的App ID开启Associated Domains服务。c)创建新的(或更新现有的)配置文件,下载并导入到XCode中。

5

配置URL Scheme:选中工程,在 TARGETS 中选择项目,点击 Info 选项,在 URL Types 添加项。点击 “+” 号,在 Identifier 中输入 “com.fm.openinstall”,在 URL Schemes 中输入 “pqbkn8, openinstall”(注意:没有双引号)。

注意事项
1

[OpenInstallSDK setAppKey:@'orx4hy' withDelegate:self]方法中的“orx4hy”需要替换为你在openinstall官网注册登录,创建应用对应的Appkey

2

代码块中的回调方法仅为测试处理,只弹窗显示后去的数据,请自行替换

推荐信息