| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- #include <stdlib.h>
- #include <string.h>
- extern "C" UIViewController *UnityGetGLViewController(void);
- static void ShowNetworkDialog(const char *message, void (*callback)(int), bool allowCancel)
- {
- NSString *text = message ? [NSString stringWithUTF8String:message] : @"";
- dispatch_async(dispatch_get_main_queue(), ^{
- UIViewController *presenter = UnityGetGLViewController();
- while (presenter.presentedViewController != nil)
- presenter = presenter.presentedViewController;
- if (presenter.isBeingDismissed || presenter.isBeingPresented)
- {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 10), dispatch_get_main_queue(), ^{
- ShowNetworkDialog([text UTF8String], callback, allowCancel);
- });
- return;
- }
- if (presenter == nil || presenter.view.window == nil)
- {
- callback(0);
- return;
- }
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Network Error"
- message:text preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:(allowCancel ? @"Retry" : @"retry") style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *action) { callback(1); }]];
- if (allowCancel)
- [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
- handler:^(UIAlertAction *action) { callback(0); }]];
- [presenter presentViewController:alert animated:YES completion:nil];
- });
- }
- extern "C"
- {
- int AppRuntimes_GetEnableUnityLog()
- {
- id value = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"EnableUnityLog"];
- if ([value isKindOfClass:[NSNumber class]] || [value isKindOfClass:[NSString class]])
- return [value boolValue] ? 1 : 0;
- return 0;
- }
- const char *AppRuntimes_GetTestUserID()
- {
- id value = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"TestUserID"];
- return strdup([value isKindOfClass:[NSString class]] ? [value UTF8String] : "");
- }
- void AppRuntimes_FreeString(const char *value)
- {
- free((void *)value);
- }
- void AppRuntimes_ShowDialog(const char *message, void (*callback)(int))
- {
- ShowNetworkDialog(message, callback, true);
- }
- void AppRuntimes_ShowRetryDialog(const char *message, void (*callback)(int))
- {
- ShowNetworkDialog(message, callback, false);
- }
- }
|