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.
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
.
**Sample code**
```objectivec
@implementation MPaaSInterface (Portal)
- (BOOL)enablePrivacyAuth
{
return YES;
}
@end
```
2. Implement permission pop-up windows.
Rewrite the- (DTFrameworkCallbackResult)application:(UIApplication *)application privacyAuthDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions completionHandler:(**void** (^)(**void**))completionHandler;
method provided by the framework.
Sample code
```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. 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:
#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:@"Privacy permissions"];
}
- (void)showAlertWithTitle:(NSString *)title
{
if ([title length] > 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", 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. 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:
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// Initialize container Context.
[MPNebulaAdapterInterface setNBContextWhenEnablePrivacyAuth];
...
}
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.
Sample code
@implementation MPaaSInterface (mPaaSdemo)
- (BOOL)enableUserOverWriteAuthAlert {
// If the user has clicked "Agree" for privacy terms, "NO" is returned, which indicates that mPaaS components can normally call relevant APIs.
// Otherwise, "Yes" is returned, which indicates that mPaaS components will hold the calls of relevant APIs.
return ![[NSUserDefaults standardUserDefaults] boolForKey:@"xx_pr"];
}
@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.
APRemoteLogging.framework
exists.Sample code (we recommend that you call it at the earliest possible time)
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:
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// Initialize container Context.
[MPNebulaAdapterInterface setNBContextWhenEnablePrivacyAuth];
...
}