cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.15k stars 7.05k forks source link

CCDirector::end on iOS can't exit app #18887

Open toreinkun opened 6 years ago

toreinkun commented 6 years ago

it is only let the app become black screen.

stevetranby commented 6 years ago

It's not meant to exit app. It releases all resources (scene, nodes, opengl context). You'll need to use something more forceful like posix exit(0).

However, note that most, if not all apps, shouldn't actually force quit like this. You don't really need to call or use Director::end yourself in iOS.

summerinsects commented 6 years ago

[HelloWorldScene.cpp] (https://github.com/cocos2d/cocos2d-x/blob/v3/tests/cpp-empty-test/Classes/HelloWorldScene.cpp)

void HelloWorld::menuCloseCallback(Ref* sender)
{
    Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}
drelaptop commented 6 years ago

As @summerinsects said, that is the solution. so close this issue.

stevetranby commented 6 years ago

Let me just reiterate that exit(0) is not meant to be used in an iOS app. It will likely fail in App Review if my experience of getting rejected for it would occur for anyone else.

Dimon4eg commented 5 years ago

If user declines privacy policy then exit(0) is ok for iOS?

stevetranby commented 5 years ago

@Dimon4eg not sure whether you meant ok or "not" ok? nor why privacy policy would matter.

I did appeal an app review and was able to get the app into the store while having an exit(0) to fully purge it from the system since it runs in the background.

Dimon4eg commented 5 years ago

@stevetranby I mean the next flow: user installs game, launches it, at start game displays "Privacy Policy" dialog to accept it by user (for GDPR). Dialog has two buttons: "Accept" and "Quit". If user presses "Quit" I do exit(0).

@drelaptop I think you can close this issue as solution is found here by @summerinsects :+1: