AppRuntimesNative.mm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #import <Foundation/Foundation.h>
  2. #import <UIKit/UIKit.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. extern "C" UIViewController *UnityGetGLViewController(void);
  6. extern "C"
  7. {
  8. int AppRuntimes_GetEnableUnityLog()
  9. {
  10. id value = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"EnableUnityLog"];
  11. if ([value isKindOfClass:[NSNumber class]] || [value isKindOfClass:[NSString class]])
  12. return [value boolValue] ? 1 : 0;
  13. return 0;
  14. }
  15. const char *AppRuntimes_GetTestUserID()
  16. {
  17. id value = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"TestUserID"];
  18. return strdup([value isKindOfClass:[NSString class]] ? [value UTF8String] : "");
  19. }
  20. void AppRuntimes_FreeString(const char *value)
  21. {
  22. free((void *)value);
  23. }
  24. void AppRuntimes_ShowDialog(const char *message, void (*callback)(int))
  25. {
  26. NSString *text = message ? [NSString stringWithUTF8String:message] : @"";
  27. dispatch_async(dispatch_get_main_queue(), ^{
  28. UIViewController *presenter = UnityGetGLViewController();
  29. while (presenter.presentedViewController != nil)
  30. presenter = presenter.presentedViewController;
  31. if (presenter == nil || presenter.view.window == nil)
  32. {
  33. callback(0);
  34. return;
  35. }
  36. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Network Error"
  37. message:text preferredStyle:UIAlertControllerStyleAlert];
  38. [alert addAction:[UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault
  39. handler:^(UIAlertAction *action) { callback(1); }]];
  40. [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
  41. handler:^(UIAlertAction *action) { callback(0); }]];
  42. [presenter presentViewController:alert animated:YES completion:nil];
  43. });
  44. }
  45. }