文档

隐私权限弹框的使用说明

更新时间:

背景

监管部门要求在用户点击隐私协议弹框中“同意” 按钮之前,App 不可以调用相关敏感 API。为应对此监管要求,mPaaS iOS 10.1.60.27 以上(60 版本) 和 10.1.32.18 以上(32 版本)的基线提供了支持,请您根据实际情况参考本文对工程进行改造。

使用方法

根据是否让 mPaaS iOS 框架托管 App 的生命周期,需要采用不同的使用方法。通过查看工程 main.m 文件中是否启用了框架的 DFApplicationDFClientDelegate,可以判断是否让 mPaaS iOS 框架托管了 App 的生命周期;启用了框架的 DFApplicationDFClientDelegate即表示进行了托管。

  1. return UIApplicationMain(argc, argv, @"DFApplication", @"DFClientDelegate"); // NOW USE MPAAS FRAMEWORK

框架托管 App 生命周期

1. 允许隐私弹框提示

MPaaSInterface category中重写以下 enablePrivacyAuth 接口方法,并返回 YES
1

  1. **代码示例**
  2. ```objectivec
  3. @implementation MPaaSInterface (Portal)
  4. - (BOOL)enablePrivacyAuth
  5. {
  6. return YES;
  7. }
  8. @end
  9. ```

2. 实现权限弹框

重写框架提供的- (DTFrameworkCallbackResult)application:(UIApplication *)application privacyAuthDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions completionHandler:(**void** (^)(**void**))completionHandler;方法。
2

代码示例

  1. ```objectivec
  2. - (DTFrameworkCallbackResult)application:(UIApplication *)application privacyAuthDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions completionHandler:(void (^)(void))completionHandler
  3. {
  4. UIWindow *authWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  5. authWindow.backgroundColor = [UIColor redColor];
  6. authWindow.windowLevel = UIWindowLevelStatusBar+5;
  7. AuthViewController *vc = [[AuthViewController alloc] init];
  8. vc.completionHandler = completionHandler;
  9. vc.window = authWindow;
  10. authWindow.rootViewController = vc;
  11. [authWindow makeKeyAndVisible];
  12. return DTFrameworkCallbackResultContinue;
  13. }
  14. ```

3. 启动 mPaaS 框架

在用户点击 同意 授权后,回调 completionHandler,继续启动 mPaaS 框架。示例代码如下所示:

  1. #import <UIKit/UIKit.h>
  2. NS_ASSUME_NONNULL_BEGIN
  3. @interface AuthViewController : UIViewController
  4. @property (nonatomic, copy) void (^completionHandler)(void);
  5. @property (nonatomic, strong) UIWindow *window;
  6. @end
  7. NS_ASSUME_NONNULL_END
  1. #import "AuthViewController.h"
  2. @interface AuthViewController ()<UIAlertViewDelegate>
  3. @end
  4. @implementation AuthViewController
  5. - (void)viewDidLoad {
  6. [super viewDidLoad];
  7. // Do any additional setup after loading the view.
  8. [self showAlertWithTitle:@"隐私权限"];
  9. }
  10. - (void)showAlertWithTitle:(NSString *)title
  11. {
  12. if ([title length] > 0) {
  13. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
  14. message:nil
  15. delegate:self
  16. cancelButtonTitle:@"取消"
  17. otherButtonTitles:@"确定", nil];
  18. [self.window makeKeyWindow];
  19. [alert show];
  20. }
  21. }
  22. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  23. {
  24. if (buttonIndex == 1) {
  25. if (self.completionHandler) {
  26. self.completionHandler();
  27. self.window.rootViewController = nil;
  28. self.window = nil;
  29. }
  30. }else {
  31. exit(0);
  32. }
  33. }
  34. @end

4. 手动初始化容器 Context

如果您集成了 H5 容器和离线包、小程序组件,则需要在 - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中手动初始化容器 Context。代码示例如下。

  1. - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. ...
  4. // 初始化容器Context
  5. [MPNebulaAdapterInterface setNBContextWhenEnablePrivacyAuth];
  6. ...
  7. }

非框架托管 App 生命周期

1. 支持隐私弹框

MPaaSInterface category 中重写 enableUserOverWriteAuthAlert 接口方法,并返回相关隐私权限状态。
4

代码示例

  1. @implementation MPaaSInterface (mPaaSdemo)
  2. - (BOOL)enableUserOverWriteAuthAlert {
  3. // 如果隐私条款用户已经点过 “同意”,这里返回 “NO”,表示 mPaaS 组件可以正常调用相关 API。
  4. // 反之,返回 “Yes”,mPaaS 组件会 hold 住相关 API 调用。
  5. return ![[NSUserDefaults standardUserDefaults] boolForKey:@"xx_pr"];
  6. }
  7. @end

2. 阻止提前上报日志埋点

如果接入过埋点相关组件,需要在启动流程中额外调用 MPAnalysisHelper holdUploadLogUntilAgreed 方法,来阻止提前上报日志埋点。

说明:可通过是否有 APRemoteLogging.framework 来判断是否接入过埋点相关组件。

代码示例(推荐在尽量早的时机调用)
5

3. 手动初始化容器 Context

如果您集成了 H5 容器和离线包、小程序组件,则需要在 - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中手动初始化容器 Context。代码示例如下。

  1. - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. ...
  4. // 初始化容器 Context
  5. [MPNebulaAdapterInterface setNBContextWhenEnablePrivacyAuth];
  6. ...
  7. }
  • 本页导读 (0)
文档反馈