All Products
Search
Document Center

Mobile Platform as a Service:Privacy permission

Last Updated:May 27, 2021

Background

The regulatory authority requires that the app cannot call sensitive relevant APIs before the user clicks the “Agree” button in the privacy agreement window. In order to meet this regulatory requirement, the baseline for mPaaS iOS 10.1.60.27 and later (60-series versions) and 10.1.32.18 and later (32-series versions) support this feature. You can modify your project as needed by referring to this document.

Usage

Different usage methods are required depending on whether the mPaaS iOS framework is allowed to host the lifecycle of the app. By checking whether DFApplication and DFClientDelegate are enabled for the framework in the main.m file of the project, you can determine whether the mPaaS iOS framework is allowed to host the lifecycle of the app. If DFApplication and DFClientDelegate are enabled, the hosting is allowed.

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

Host the lifecycle of the app by the framework

1. Allow privacy pop-up prompts.

In MPaaSInterface category, rewrite the enablePrivacyAuth API method and return YES.
1

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

2. Implement permission pop-up windows.

Rewrite the- (DTFrameworkCallbackResult)application:(UIApplication *)application privacyAuthDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions completionHandler:(**void** (^)(**void**))completionHandler; method provided by the framework.
2

Sample code

  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. Start the mPaaS framework.

After the user clicks Agree for authorization, call back completionHandler to continue to start the mPaaS framework. The sample code is as follows:

  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:@"Privacy permissions"];
  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:@"Cancel"
  17. otherButtonTitles:@"OK", 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. Manually initialize container Context.

If you have integrated the HTML5 container, offline package, and mini program components, you must manually initialize container Context in the - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions method. The code sample is as follows:

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

Host the lifecycle of the app not by the framework

1. Support privacy pop-up windows.

In MPaaSInterface category, rewrite the enableUserOverWriteAuthAlert API method and return the corresponding privacy permission status.
4

Sample code

  1. @implementation MPaaSInterface (mPaaSdemo)
  2. - (BOOL)enableUserOverWriteAuthAlert {
  3. // If the user has clicked "Agree" for privacy terms, "NO" is returned, which indicates that mPaaS components can normally call relevant APIs.
  4. // Otherwise, "Yes" is returned, which indicates that mPaaS components will hold the calls of relevant APIs.
  5. return ![[NSUserDefaults standardUserDefaults] boolForKey:@"xx_pr"];
  6. }
  7. @end

2. Prevent the early reporting of log tracking.

If you have accessed tracking-related components, you must call the MPAnalysisHelper holdUploadLogUntilAgreed method in the startup process to prevent the early reporting of log tracking.

Note: You can determine whether tracking-related components have been accessed by checking whether APRemoteLogging.framework exists.

Sample code (we recommend that you call it at the earliest possible time)
5

3. Manually initialize container Context.

If you have integrated the HTML5 container, offline package, and mini program components, you must manually initialize container Context in the - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions method. The code sample is as follows:

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