全部产品
Search
文档中心

移动开发平台mPaaS:隐私权限弹框的使用说明

更新时间:Dec 11, 2025

背景

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

使用方法

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

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

框架托管 App 生命周期

1. 允许隐私弹框提示

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

**代码示例**

```objectivec
@implementation MPaaSInterface (Portal)

- (BOOL)enablePrivacyAuth
{
    return YES;
}

@end
```

2. 实现权限弹框

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

代码示例

```objectivec
- (DTFrameworkCallbackResult)application:(UIApplication *)application privacyAuthDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions completionHandler:(void (^)(void))completionHandler
{
    UIWindow *authWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    authWindow.backgroundColor = [UIColor redColor];
    authWindow.windowLevel = UIWindowLevelStatusBar+5;
    AuthViewController *vc = [[AuthViewController alloc] init];
    vc.completionHandler = completionHandler;
    vc.window = authWindow;
    authWindow.rootViewController = vc;
    [authWindow makeKeyAndVisible];

    return DTFrameworkCallbackResultContinue;
}
```

3. 启动 mPaaS 框架

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

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface AuthViewController : UIViewController

@property (nonatomic, copy) void (^completionHandler)(void);
@property (nonatomic, strong) UIWindow *window;

@end

NS_ASSUME_NONNULL_END
#import "AuthViewController.h"

@interface AuthViewController ()<UIAlertViewDelegate>

@end

@implementation AuthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self showAlertWithTitle:@"隐私权限"];
}

- (void)showAlertWithTitle:(NSString *)title
{
    if ([title length] > 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                        message:nil
                                                       delegate:self
                                              cancelButtonTitle:@"取消"
                                              otherButtonTitles:@"确定", nil];
        [self.window makeKeyWindow];
        [alert show];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        if (self.completionHandler) {
            self.completionHandler();
            self.window.rootViewController = nil;
            self.window = nil;
        }
    }else {
        exit(0);
    }
}



@end

4. 手动初始化容器 Context

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

- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  // 初始化容器Context
  [MPNebulaAdapterInterface setNBContextWhenEnablePrivacyAuth];    

  ...
}

非框架托管 App 生命周期

1. 支持隐私弹框

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

代码示例

    @implementation MPaaSInterface (mPaaSdemo)

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

    @end

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

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

说明

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

代码示例

推荐在尽量早的时机调用。5

3. 手动初始化容器 Context

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

- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  // 初始化容器 Context
  [MPNebulaAdapterInterface setNBContextWhenEnablePrivacyAuth];    

  ...
}