Skip to content

Commit ef16d4f

Browse files
wanghehackerminggo
authored andcommitted
[iOS]Screen Time would makes App stuck sometimes (#20313)
* Screen Time would prevent UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification from being fired until reboot the iPad. * code format fix
1 parent 596da2d commit ef16d4f

File tree

12 files changed

+104
-15
lines changed

12 files changed

+104
-15
lines changed

cocos/platform/ios/CCDirectorCaller-ios.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ - (instancetype)init
7676
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
7777
[nc addObserver:self selector:@selector(appDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
7878
[nc addObserver:self selector:@selector(appDidBecomeInactive) name:UIApplicationWillResignActiveNotification object:nil];
79+
[nc addObserver:self selector:@selector(appDidBecomeActive) name:UIApplicationWillEnterForegroundNotification object:nil];
80+
[nc addObserver:self selector:@selector(appDidBecomeInactive) name:UIApplicationDidEnterBackgroundNotification object:nil];
7981

8082
self.interval = 1;
8183
}
@@ -158,6 +160,12 @@ -(void)initLastDisplayTime
158160
lastDisplayTime = (mach_absolute_time() / clockFrequency) - ((1.0 / 60) * self.interval);
159161
}
160162

163+
//
164+
-(void)setActive:(BOOL)isActive
165+
{
166+
isAppActive = isActive;
167+
}
168+
161169
@end
162170

163171
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS

templates/cpp-template-default/proj.ios_mac/ios/RootViewController.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
2727
#import "RootViewController.h"
2828
#import "cocos2d.h"
2929
#import "platform/ios/CCEAGLView-ios.h"
30+
#import "platform/ios/CCDirectorCaller-ios.h"
3031

3132

3233
@implementation RootViewController
@@ -68,6 +69,13 @@ - (void)viewWillAppear:(BOOL)animated {
6869
[super viewWillAppear:animated];
6970
}
7071

72+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
73+
//so we need to active CCDirectorCaller manually
74+
-(void)viewDidAppear:(BOOL)animated{
75+
[super viewDidAppear:animated];
76+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
77+
}
78+
7179
- (void)viewDidDisappear:(BOOL)animated {
7280
[super viewDidDisappear:animated];
7381
}

templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
2727
#import "RootViewController.h"
2828
#import "cocos2d.h"
2929
#import "platform/ios/CCEAGLView-ios.h"
30+
#import "platform/ios/CCDirectorCaller-ios.h"
3031

3132

3233
@implementation RootViewController
@@ -68,6 +69,13 @@ - (void)viewWillAppear:(BOOL)animated {
6869
[super viewWillAppear:animated];
6970
}
7071

72+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
73+
//so we need to active CCDirectorCaller manually
74+
-(void)viewDidAppear:(BOOL)animated{
75+
[super viewDidAppear:animated];
76+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
77+
}
78+
7179
- (void)viewDidDisappear:(BOOL)animated {
7280
[super viewDidDisappear:animated];
7381
}

templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
2727
#import "RootViewController.h"
2828
#import "cocos2d.h"
2929
#import "platform/ios/CCEAGLView-ios.h"
30+
#import "platform/ios/CCDirectorCaller-ios.h"
3031

3132

3233
@implementation RootViewController
@@ -68,6 +69,13 @@ - (void)viewWillAppear:(BOOL)animated {
6869
[super viewWillAppear:animated];
6970
}
7071

72+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
73+
//so we need to active CCDirectorCaller manually
74+
-(void)viewDidAppear:(BOOL)animated{
75+
[super viewDidAppear:animated];
76+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
77+
}
78+
7179
- (void)viewDidDisappear:(BOOL)animated {
7280
[super viewDidDisappear:animated];
7381
}

tests/cpp-empty-test/proj.ios/RootViewController.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
****************************************************************************/
2626

2727
#import "RootViewController.h"
28-
28+
#import "platform/ios/CCDirectorCaller-ios.h"
2929

3030
@implementation RootViewController
3131

@@ -50,8 +50,15 @@ - (void)loadView {
5050
- (void)viewDidLoad {
5151
[super viewDidLoad];
5252
}
53-
5453
*/
54+
55+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
56+
//so we need to active CCDirectorCaller manually
57+
-(void)viewDidAppear:(BOOL)animated{
58+
[super viewDidAppear:animated];
59+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
60+
}
61+
5562
// Override to allow orientations other than the default portrait orientation.
5663
// This method is deprecated on ios6
5764
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

tests/cpp-tests/proj.ios/Classes/RootViewController.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
****************************************************************************/
2626

2727
#import "RootViewController.h"
28-
28+
#import "platform/ios/CCDirectorCaller-ios.h"
2929

3030
@implementation RootViewController
3131

@@ -50,8 +50,15 @@ - (void)loadView {
5050
- (void)viewDidLoad {
5151
[super viewDidLoad];
5252
}
53-
5453
*/
54+
55+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
56+
//so we need to active CCDirectorCaller manually
57+
-(void)viewDidAppear:(BOOL)animated{
58+
[super viewDidAppear:animated];
59+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
60+
}
61+
5562
// Override to allow orientations other than the default portrait orientation.
5663
// This method is deprecated on ios6
5764
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

tests/game-controller-test/proj.ios/RootViewController.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
****************************************************************************/
2626

2727
#import "RootViewController.h"
28-
28+
#import "platform/ios/CCDirectorCaller-ios.h"
2929

3030
@implementation RootViewController
3131

@@ -50,8 +50,15 @@ - (void)loadView {
5050
- (void)viewDidLoad {
5151
[super viewDidLoad];
5252
}
53-
5453
*/
54+
55+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
56+
//so we need to active CCDirectorCaller manually
57+
-(void)viewDidAppear:(BOOL)animated{
58+
[super viewDidAppear:animated];
59+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
60+
}
61+
5562
// Override to allow orientations other than the default portrait orientation.
5663
// This method is deprecated on ios6
5764
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

tests/js-tests/project/proj.ios/RootViewController.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import "RootViewController.h"
10-
10+
#import "platform/ios/CCDirectorCaller-ios.h"
1111

1212
@implementation RootViewController
1313

@@ -32,8 +32,15 @@ - (void)loadView {
3232
- (void)viewDidLoad {
3333
[super viewDidLoad];
3434
}
35-
3635
*/
36+
37+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
38+
//so we need to active CCDirectorCaller manually
39+
-(void)viewDidAppear:(BOOL)animated{
40+
[super viewDidAppear:animated];
41+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
42+
}
43+
3744
// Override to allow orientations other than the default portrait orientation.
3845
// This method is deprecated on ios6
3946
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

tests/lua-empty-test/project/proj.ios/RootViewController.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
****************************************************************************/
2626

2727
#import "RootViewController.h"
28-
28+
#import "platform/ios/CCDirectorCaller-ios.h"
2929

3030
@implementation RootViewController
3131

@@ -50,8 +50,15 @@ - (void)loadView {
5050
- (void)viewDidLoad {
5151
[super viewDidLoad];
5252
}
53-
5453
*/
54+
55+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
56+
//so we need to active CCDirectorCaller manually
57+
-(void)viewDidAppear:(BOOL)animated{
58+
[super viewDidAppear:animated];
59+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
60+
}
61+
5562
// Override to allow orientations other than the default portrait orientation.
5663
// This method is deprecated on ios6
5764
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

tests/lua-game-controller-test/project/proj.ios/RootViewController.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
****************************************************************************/
2626

2727
#import "RootViewController.h"
28-
28+
#import "platform/ios/CCDirectorCaller-ios.h"
2929

3030
@implementation RootViewController
3131

@@ -50,8 +50,15 @@ - (void)loadView {
5050
- (void)viewDidLoad {
5151
[super viewDidLoad];
5252
}
53-
5453
*/
54+
55+
//In iOS 12.0+, Screen Time's bug cause UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification do not fired
56+
//so we need to active CCDirectorCaller manually
57+
-(void)viewDidAppear:(BOOL)animated{
58+
[super viewDidAppear:animated];
59+
[[CCDirectorCaller sharedDirectorCaller] setActive:YES];
60+
}
61+
5562
// Override to allow orientations other than the default portrait orientation.
5663
// This method is deprecated on ios6
5764
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

0 commit comments

Comments
 (0)