diff --git a/cocos/platform/ios/CCDirectorCaller-ios.mm b/cocos/platform/ios/CCDirectorCaller-ios.mm index 14d39d9cc9ac..7e9b5da0fa24 100644 --- a/cocos/platform/ios/CCDirectorCaller-ios.mm +++ b/cocos/platform/ios/CCDirectorCaller-ios.mm @@ -76,6 +76,8 @@ - (instancetype)init NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(appDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; [nc addObserver:self selector:@selector(appDidBecomeInactive) name:UIApplicationWillResignActiveNotification object:nil]; + [nc addObserver:self selector:@selector(appDidBecomeActive) name:UIApplicationWillEnterForegroundNotification object:nil]; + [nc addObserver:self selector:@selector(appDidBecomeInactive) name:UIApplicationDidEnterBackgroundNotification object:nil]; self.interval = 1; } @@ -158,6 +160,12 @@ -(void)initLastDisplayTime lastDisplayTime = (mach_absolute_time() / clockFrequency) - ((1.0 / 60) * self.interval); } +// +-(void)setActive:(BOOL)isActive +{ + isAppActive = isActive; +} + @end #endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS diff --git a/templates/cpp-template-default/proj.ios_mac/ios/RootViewController.mm b/templates/cpp-template-default/proj.ios_mac/ios/RootViewController.mm index 7f5ca28f740f..e3c7fcb301a6 100644 --- a/templates/cpp-template-default/proj.ios_mac/ios/RootViewController.mm +++ b/templates/cpp-template-default/proj.ios_mac/ios/RootViewController.mm @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal #import "RootViewController.h" #import "cocos2d.h" #import "platform/ios/CCEAGLView-ios.h" +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -68,6 +69,13 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index 8c6969f1619b..dbede85f0ba8 100644 --- a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal #import "RootViewController.h" #import "cocos2d.h" #import "platform/ios/CCEAGLView-ios.h" +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -68,6 +69,13 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index 8c6969f1619b..dbede85f0ba8 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal #import "RootViewController.h" #import "cocos2d.h" #import "platform/ios/CCEAGLView-ios.h" +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -68,6 +69,13 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } diff --git a/tests/cpp-empty-test/proj.ios/RootViewController.mm b/tests/cpp-empty-test/proj.ios/RootViewController.mm index 9032b654371d..7d2df0607488 100644 --- a/tests/cpp-empty-test/proj.ios/RootViewController.mm +++ b/tests/cpp-empty-test/proj.ios/RootViewController.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal ****************************************************************************/ #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -50,8 +50,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/cpp-tests/proj.ios/Classes/RootViewController.mm b/tests/cpp-tests/proj.ios/Classes/RootViewController.mm index 3f484988f3a8..3c3b0cbefe41 100644 --- a/tests/cpp-tests/proj.ios/Classes/RootViewController.mm +++ b/tests/cpp-tests/proj.ios/Classes/RootViewController.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal ****************************************************************************/ #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -50,8 +50,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/game-controller-test/proj.ios/RootViewController.mm b/tests/game-controller-test/proj.ios/RootViewController.mm index 9032b654371d..7d2df0607488 100644 --- a/tests/game-controller-test/proj.ios/RootViewController.mm +++ b/tests/game-controller-test/proj.ios/RootViewController.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal ****************************************************************************/ #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -50,8 +50,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/js-tests/project/proj.ios/RootViewController.mm b/tests/js-tests/project/proj.ios/RootViewController.mm index 0e1952eafdfd..4bcdbde169fc 100644 --- a/tests/js-tests/project/proj.ios/RootViewController.mm +++ b/tests/js-tests/project/proj.ios/RootViewController.mm @@ -7,7 +7,7 @@ // #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -32,8 +32,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/lua-empty-test/project/proj.ios/RootViewController.mm b/tests/lua-empty-test/project/proj.ios/RootViewController.mm index 8002ff82d09b..ea3cc791e21e 100644 --- a/tests/lua-empty-test/project/proj.ios/RootViewController.mm +++ b/tests/lua-empty-test/project/proj.ios/RootViewController.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal ****************************************************************************/ #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -50,8 +50,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/lua-game-controller-test/project/proj.ios/RootViewController.mm b/tests/lua-game-controller-test/project/proj.ios/RootViewController.mm index 8002ff82d09b..ea3cc791e21e 100644 --- a/tests/lua-game-controller-test/project/proj.ios/RootViewController.mm +++ b/tests/lua-game-controller-test/project/proj.ios/RootViewController.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal ****************************************************************************/ #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -50,8 +50,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/lua-tests/project/proj.ios_mac/ios/RootViewController.mm b/tests/lua-tests/project/proj.ios_mac/ios/RootViewController.mm index 8002ff82d09b..ea3cc791e21e 100644 --- a/tests/lua-tests/project/proj.ios_mac/ios/RootViewController.mm +++ b/tests/lua-tests/project/proj.ios_mac/ios/RootViewController.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal ****************************************************************************/ #import "RootViewController.h" - +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -50,8 +50,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/tests/performance-tests/proj.ios/RootViewController.mm b/tests/performance-tests/proj.ios/RootViewController.mm index 98b34173d3ce..b8129a1047ba 100644 --- a/tests/performance-tests/proj.ios/RootViewController.mm +++ b/tests/performance-tests/proj.ios/RootViewController.mm @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal #import "RootViewController.h" #import "cocos2d.h" #import "platform/ios/CCEAGLView-ios.h" +#import "platform/ios/CCDirectorCaller-ios.h" @implementation RootViewController @@ -51,8 +52,15 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; } - */ + +//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired +//so we need to active CCDirectorCaller manually +-(void)viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [[CCDirectorCaller sharedDirectorCaller] setActive:YES]; +} + // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {