問題:有時候嗜价,我們在做App項(xiàng)目時艇抠,不需要做注冊登錄頁面
??,但是久锥,這個App必須要有隱私政策和用戶協(xié)議
家淤。所以,在第一次打開App時瑟由,就需要先進(jìn)入到隱私政策
頁面媒鼓。
1、首先错妖,自定義一個UIViewController
绿鸣,可以在這個UIViewController
上自定義一些按鈕或其他內(nèi)容,點(diǎn)擊按鈕可以直接到加載HTML
格式的隱私政策WKWebView
頁面:
GW_PrivacyPolicy_VC.h:
@interface GW_PrivacyPolicy_VC : GWBaseViewController
/**
* 同意隱私政策之后暂氯,繼續(xù)潮模,拒絕,提示:APP不可用
*/
@property (nonatomic, copy) void (^agreePrivacyPolicy_Block) (BOOL is_Agree);
@end
GW_PrivacyPolicy_VC.m:
#import "GW_PrivacyPolicy_VC.h"
#import "GW_PrivacyPolicy_PopView.h" // 隱私政策 彈窗
@interface GW_PrivacyPolicy_VC ()
@end
@implementation GW_PrivacyPolicy_VC
- (void)viewDidLoad {
[super viewDidLoad];
self.statusBg.hidden = YES;
self.leftButton.hidden = YES;
self.rightButton.hidden = YES;
self.navigationBar.hidden = YES;
__weak typeof(self)weakSelf = self;
GW_PrivacyPolicy_PopView *popView = [[GW_PrivacyPolicy_PopView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.view addSubview:popView];
popView.agreePrivacyPolicy_ContinueBlock = ^(BOOL is_Agree) { // 同意痴施,繼續(xù)代碼
if (weakSelf.agreePrivacyPolicy_Block) {
weakSelf.agreePrivacyPolicy_Block(is_Agree);
}
};
return;
}
@end
2擎厢、使用:將這個自定義的UIViewController
在AppDelegate.m
中跳轉(zhuǎn),
- 原理:在打開App時辣吃,先判斷其是否已經(jīng)同意“隱私政策”动遭,如果同意就跳到首頁,否則神得,就是沒同意厘惦,跳到“隱私政策”頁面,不同意哩簿,無法使用改App宵蕉。
AppDelegate.h:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m:
#import "AppDelegate.h"
#import "KMainTabBarController.h"
#import "GW_PrivacyPolicy_VC.h"
@interface AppDelegate ()
@property (nonatomic, strong) KMainTabBarController *mainTabBarController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.mainTabBarController = [[KMainTabBarController alloc] init];
self.window.rootViewController = self.mainTabBarController;
[self.window makeKeyAndVisible];
// 判斷是否有保存到本地的標(biāo)志:NSUserDefaults(同意“隱私政策” 保存1,否則就是nil或0)
NSString *is_AgreeStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"is_Agree_App_PrivacyPolicy"];
if (![is_AgreeStr isEqualToString:@"1"]) {
GW_PrivacyPolicy_VC *privacyPolicyVC = [[GW_PrivacyPolicy_VC alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:privacyPolicyVC];
privacyPolicyVC.agreePrivacyPolicy_Block = ^(BOOL is_Agree) {
// 同意隱私政策之后节榜,再跳轉(zhuǎn)首頁
self.mainTabBarController.selectedIndex = 0;
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.mainTabBarController];
self.mainTabBarController.navigationController.navigationBarHidden = YES; // (如果首頁不帶 系統(tǒng)導(dǎo)航欄 的話)不添加這一行的話羡玛,第一次運(yùn)行會有導(dǎo)航欄,是其上面那一行造成的
// 定位權(quán)限(獲取定位)(這種操作宗苍,在進(jìn)入頁面之后在判斷)
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
};
} else {
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}
return YES;
}
@end