ios.mm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*************************************************************************/
  2. /* ios.mm */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "ios.h"
  31. #import "app_delegate.h"
  32. #import "view_controller.h"
  33. #import <UIKit/UIKit.h>
  34. #include <sys/sysctl.h>
  35. void iOS::_bind_methods() {
  36. ClassDB::bind_method(D_METHOD("get_rate_url", "app_id"), &iOS::get_rate_url);
  37. };
  38. void iOS::alert(const char *p_alert, const char *p_title) {
  39. NSString *title = [NSString stringWithUTF8String:p_title];
  40. NSString *message = [NSString stringWithUTF8String:p_alert];
  41. UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  42. UIAlertAction *button = [UIAlertAction actionWithTitle:@"OK"
  43. style:UIAlertActionStyleCancel
  44. handler:^(id){
  45. }];
  46. [alert addAction:button];
  47. [AppDelegate.viewController presentViewController:alert animated:YES completion:nil];
  48. }
  49. String iOS::get_model() const {
  50. // [[UIDevice currentDevice] model] only returns "iPad" or "iPhone".
  51. size_t size;
  52. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  53. char *model = (char *)malloc(size);
  54. if (model == NULL) {
  55. return "";
  56. }
  57. sysctlbyname("hw.machine", model, &size, NULL, 0);
  58. NSString *platform = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
  59. free(model);
  60. const char *str = [platform UTF8String];
  61. return String::utf8(str != nullptr ? str : "");
  62. }
  63. String iOS::get_rate_url(int p_app_id) const {
  64. String app_url_path = "itms-apps://itunes.apple.com/app/idAPP_ID";
  65. String ret = app_url_path.replace("APP_ID", String::num(p_app_id));
  66. printf("returning rate url %ls\n", ret.c_str());
  67. return ret;
  68. };
  69. iOS::iOS(){};