WentingLicense.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // WentingLicense.m
  3. // Unity-iPhone
  4. //
  5. // Created by 吴博 on 2021/7/23.
  6. //
  7. #import "WentingLicense.h"
  8. #import "WentingLicenseViewController.h"
  9. #import "UnityAppController.h"
  10. #define kWentingLicenseAgreeStatus @"WentingLicenseAgreeStatus"
  11. extern UnityAppController* _UnityAppController;
  12. extern bool _unityAppReady;
  13. @interface WentingLicense() <UIApplicationDelegate>
  14. @property (nonatomic, assign) BOOL agreeStatus;
  15. @property (nonatomic, assign) BOOL checked;
  16. @property (nonatomic, strong) WentingLicenseViewController *controller;
  17. @property (nonatomic, strong) NSDictionary *launchOptions;
  18. @end
  19. @implementation WentingLicense
  20. + (instancetype)sharedInstance {
  21. static WentingLicense *license = nil;
  22. static dispatch_once_t onceToken;
  23. dispatch_once(&onceToken, ^{
  24. license = [[WentingLicense alloc] init];
  25. });
  26. return license;
  27. }
  28. - (BOOL)CheckAgreeWithLaunchOptions:(NSDictionary*)launchOptions {
  29. self.agreeStatus = YES;//[[NSUserDefaults standardUserDefaults] boolForKey:kWentingLicenseAgreeStatus];
  30. if (self.agreeStatus) {
  31. if (self.checked) {
  32. [self.controller remove];
  33. self.controller = nil;
  34. }
  35. return NO;
  36. }
  37. if (!self.checked) {
  38. self.checked = YES;
  39. [UIApplication sharedApplication].delegate = self;
  40. }
  41. self.launchOptions = launchOptions;
  42. if (self.controller == nil) {
  43. self.controller = [[WentingLicenseViewController alloc] init];
  44. __weak WentingLicense *weakSelf = self;
  45. self.controller.cancelAction = ^{
  46. [weakSelf cancelAgreeLicense];
  47. };
  48. self.controller.confirmAction = ^{
  49. [weakSelf confirmAgreeLicense];
  50. };
  51. }
  52. return YES;
  53. }
  54. - (void)cancelAgreeLicense {
  55. exit(0);
  56. }
  57. - (void)confirmAgreeLicense {
  58. [[NSUserDefaults standardUserDefaults] setBool:true forKey:kWentingLicenseAgreeStatus];
  59. [UIApplication sharedApplication].delegate = _UnityAppController;
  60. [_UnityAppController application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions];
  61. [_UnityAppController applicationDidBecomeActive:[UIApplication sharedApplication]];
  62. }
  63. @end