Skip to content

Commit 885fcb4

Browse files
committed
fix deprecated iOS alert view
1 parent 987bd87 commit 885fcb4

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

cocos/platform/ios/CCCommon-ios.mm

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,32 @@ of this software and associated documentation files (the "Software"), to deal
4141
// ios no MessageBox, use log instead
4242
void ccMessageBox(const char * msg, const char * title)
4343
{
44-
// only enable it on iOS.
45-
// FIXME: Implement it for tvOS
46-
#if !defined(CC_TARGET_OS_TVOS)
4744
NSString * tmpTitle = (title) ? [NSString stringWithUTF8String : title] : nil;
4845
NSString * tmpMsg = (msg) ? [NSString stringWithUTF8String : msg] : nil;
49-
UIAlertView * messageBox = [[UIAlertView alloc] initWithTitle: tmpTitle
50-
message: tmpMsg
51-
delegate: nil
52-
cancelButtonTitle: @"OK"
53-
otherButtonTitles: nil];
54-
[messageBox autorelease];
55-
[messageBox show];
56-
#endif
5746

47+
// UIAlertView * messageBox = [[UIAlertView alloc] initWithTitle: tmpTitle
48+
// message: tmpMsg
49+
// delegate: nil
50+
// cancelButtonTitle: @"OK"
51+
// otherButtonTitles: nil];
52+
// [messageBox autorelease];
53+
// [messageBox show];
54+
55+
// TODO: STEVE: deprecated use this instead:
56+
UIAlertController* alert = [UIAlertController alertControllerWithTitle:tmpTitle message:tmpMsg preferredStyle:UIAlertControllerStyleAlert];
57+
58+
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK"
59+
style:UIAlertActionStyleDefault
60+
handler:^(UIAlertAction * action) {
61+
[alert dismissViewControllerAnimated:YES completion:nil];
62+
}];
63+
64+
[alert addAction:ok];
65+
66+
UIApplication* app = [UIApplication sharedApplication];
67+
UIWindow* win = [app keyWindow];
68+
UIViewController* vc = [win rootViewController];
69+
[vc presentViewController:alert animated:YES completion:nil];
5870
}
5971

6072
void LuaLog(const char * format)

0 commit comments

Comments
 (0)