Merge pull request #32326 from starryalley/ios_get_model_name

ios: support get_model_name
This commit is contained in:
Rémi Verschelde 2019-10-25 07:41:28 +02:00 committed by GitHub
commit 86abf62e48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 3 deletions

View file

@ -42,6 +42,7 @@ class iOS : public Object {
public:
static void alert(const char *p_alert, const char *p_title);
String get_model() const;
String get_rate_url(int p_app_id) const;
iOS();

View file

@ -29,6 +29,7 @@
/*************************************************************************/
#include "ios.h"
#include <sys/sysctl.h>
#import <UIKit/UIKit.h>
@ -42,6 +43,21 @@ void iOS::alert(const char *p_alert, const char *p_title) {
[alert show];
}
String iOS::get_model() const {
// [[UIDevice currentDevice] model] only returns "iPad" or "iPhone".
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = (char *)malloc(size);
if (model == NULL) {
return "";
}
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
const char *str = [platform UTF8String];
return String(str != NULL ? str : "");
}
String iOS::get_rate_url(int p_app_id) const {
String templ = "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID";
String templ_iOS7 = "itms-apps://itunes.apple.com/app/idAPP_ID";

View file

@ -47,8 +47,6 @@
#include "semaphore_iphone.h"
#include "ios.h"
#include <dlfcn.h>
int OSIPhone::get_video_driver_count() const {
@ -184,7 +182,8 @@ Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p
Engine::get_singleton()->add_singleton(Engine::Singleton("ICloud", icloud));
//icloud->connect();
#endif
Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", memnew(iOS)));
ios = memnew(iOS);
Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", ios));
return OK;
};
@ -507,6 +506,15 @@ String OSIPhone::get_name() const {
return "iOS";
};
String OSIPhone::get_model_name() const {
String model = ios->get_model();
if (model != "")
return model;
return OS_Unix::get_model_name();
}
Size2 OSIPhone::get_window_size() const {
return Vector2(video_mode.width, video_mode.height);

View file

@ -41,6 +41,7 @@
#include "game_center.h"
#include "icloud.h"
#include "in_app_store.h"
#include "ios.h"
#include "main/input_default.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
@ -72,6 +73,7 @@ private:
#ifdef ICLOUD_ENABLED
ICloud *icloud;
#endif
iOS *ios;
MainLoop *main_loop;
@ -178,6 +180,7 @@ public:
void set_data_dir(String p_dir);
virtual String get_name() const;
virtual String get_model_name() const;
Error shell_open(String p_uri);