MobLinkPro-Pure-for-IOS
MobLinkPro 无 Hook 版本
安装
pod 'mob_linksdk_pro_pure'
这是 moblinkPro 不 hook 系统方法的版本,需要开发者自己在 scheme 或 universallink 跳转时,将事件传递给 MoblinkPro,进行后续处理。
如果您没有适配 UIScene 分屏,则在 AppDelegate 调用以下方法
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
[MobLink application:application handleOpenURL:url];
return YES;;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
[MobLink application:application continueUserActivity:userActivity];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
[MobLink application:application handleOpenURL:url];
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
[MobLink application:app handleOpenURL:url];
return YES;
}
如果您适配了 UIScene 分屏,则在 SceneDelegate 调用以下方法
- (void)scene:(id)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self.window showOnScene:scene];
//在此处理是因为适配 UIScene后,冷启动App,不会走下面两个方法,需要在此处获取冷启动参数,并处理
[MobLink application:scene continueUserActivity:connectionOptions.userActivities.anyObject];
[MobLink application:scene handleOpenURL:connectionOptions.URLContexts.anyObject.URL];
}
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts API_AVAILABLE(ios(13.0)){
[MobLink application:scene handleOpenURL:URLContexts.anyObject.URL];
}
- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity API_AVAILABLE(ios(13.0)){
[MobLink application:scene continueUserActivity:userActivity];
}
MobLink 如果有场景还原事件发生,会回调代理
- (void)IMLSDKWillRestoreScene:(MLSDKScene *)scene Restore:(void (^)(BOOL, RestoreStyle))restoreHandler
{
dispatch_async(self.guideQueue, ^{
if (!self.isAlreadyRun)
{
dispatch_semaphore_wait(self.guideSemaphore, DISPATCH_TIME_FOREVER);
}
dispatch_async(dispatch_get_main_queue(), ^{
restoreHandler(YES, MLPush);
});
});
// 发送场景还原记录
if (scene.params && [scene.params isKindOfClass:[NSDictionary class]])
{
NSString *otherId = scene.params[@"id"];
if (otherId)
{
MLDSceneType sourceType = MLDSceneTypeOthers;
if (scene.params[@"scene"])
{
sourceType = [scene.params[@"scene"] integerValue];
}
[[MLDNetworkManager sharedManager] sendSceneLogWithCurrentUserID:[MLDUserManager sharedManager].currentUserId otherUserID:otherId sourceType:sourceType completion:^(BOOL success) {
if (success)
{
NSLog(@"上传场景记录成功");
}
}];
}
}
注意,该方法的回调可能不在主线程,如果开发者操作 UI,需要手动切换回主线程执行
- (void)IMLSDKWillRestoreScene:(MLSDKScene *)scene Restore:(void (^)(BOOL, RestoreStyle))restoreHandler { dispatch_async(dispatch_get_main_queue(), ^{
}); }