// // WentingLicense.m // Unity-iPhone // // Created by 吴博 on 2021/7/23. // #import "WentingLicense.h" #import "WentingLicenseViewController.h" #import "UnityAppController.h" #define kWentingLicenseAgreeStatus @"WentingLicenseAgreeStatus" extern UnityAppController* _UnityAppController; extern bool _unityAppReady; @interface WentingLicense() @property (nonatomic, assign) BOOL agreeStatus; @property (nonatomic, assign) BOOL checked; @property (nonatomic, strong) WentingLicenseViewController *controller; @property (nonatomic, strong) NSDictionary *launchOptions; @end @implementation WentingLicense + (instancetype)sharedInstance { static WentingLicense *license = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ license = [[WentingLicense alloc] init]; }); return license; } - (BOOL)CheckAgreeWithLaunchOptions:(NSDictionary*)launchOptions { self.agreeStatus = YES;//[[NSUserDefaults standardUserDefaults] boolForKey:kWentingLicenseAgreeStatus]; if (self.agreeStatus) { if (self.checked) { [self.controller remove]; self.controller = nil; } return NO; } if (!self.checked) { self.checked = YES; [UIApplication sharedApplication].delegate = self; } self.launchOptions = launchOptions; if (self.controller == nil) { self.controller = [[WentingLicenseViewController alloc] init]; __weak WentingLicense *weakSelf = self; self.controller.cancelAction = ^{ [weakSelf cancelAgreeLicense]; }; self.controller.confirmAction = ^{ [weakSelf confirmAgreeLicense]; }; } return YES; } - (void)cancelAgreeLicense { exit(0); } - (void)confirmAgreeLicense { [[NSUserDefaults standardUserDefaults] setBool:true forKey:kWentingLicenseAgreeStatus]; [UIApplication sharedApplication].delegate = _UnityAppController; [_UnityAppController application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions]; [_UnityAppController applicationDidBecomeActive:[UIApplication sharedApplication]]; } @end