Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS]Screen Time would makes App stuck sometimes #20313

Merged
merged 3 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cocos/platform/ios/CCDirectorCaller-ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CCDirectorCaller-ios.mm already listen UIApplicationWillEnterForegroundNotification event, why need these codes too?

Copy link
Contributor Author

@wanghehacker wanghehacker Nov 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CCDirectorCaller-ios.mm already listen UIApplicationWillEnterForegroundNotification event, why need these codes too?

When the App starts up cold,UIApplicationWillEnterForegroundNotification would not be triggered . But the viewDidAppear would be called.

https://developer.apple.com/documentation/uikit/uiapplicationwillenterforegroundnotification?language=objc.


- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
}
Expand Down
11 changes: 9 additions & 2 deletions tests/cpp-empty-test/proj.ios/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions tests/cpp-tests/proj.ios/Classes/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions tests/game-controller-test/proj.ios/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions tests/js-tests/project/proj.ios/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "RootViewController.h"

#import "platform/ios/CCDirectorCaller-ios.h"

@implementation RootViewController

Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions tests/lua-empty-test/project/proj.ios/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions tests/lua-tests/project/proj.ios_mac/ios/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion tests/performance-tests/proj.ios/RootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down