2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* app_delegate.mm */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-02 05:01:57 +08:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 06:11:42 +08:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#import "app_delegate.h"
|
|
|
|
|
2017-02-21 11:05:15 +08:00
|
|
|
#include "core/global_config.h"
|
2017-04-09 20:18:49 +08:00
|
|
|
#import "gl_view.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
#include "main/main.h"
|
2017-04-09 20:18:49 +08:00
|
|
|
#include "os_iphone.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2014-04-10 11:18:27 +08:00
|
|
|
#ifdef MODULE_FACEBOOKSCORER_IOS_ENABLED
|
2014-02-10 09:10:30 +08:00
|
|
|
#include "modules/FacebookScorer_ios/FacebookScorer.h"
|
|
|
|
#endif
|
|
|
|
|
2014-07-02 11:09:36 +08:00
|
|
|
#ifdef MODULE_GAME_ANALYTICS_ENABLED
|
|
|
|
#import "modules/game_analytics/ios/MobileAppTracker.framework/Headers/MobileAppTracker.h"
|
|
|
|
//#import "modules/game_analytics/ios/MobileAppTracker.h"
|
|
|
|
#import <AdSupport/AdSupport.h>
|
|
|
|
#endif
|
|
|
|
|
2015-09-04 10:24:55 +08:00
|
|
|
#ifdef MODULE_PARSE_ENABLED
|
|
|
|
#import "FBSDKCoreKit/FBSDKCoreKit.h"
|
2017-04-09 20:18:49 +08:00
|
|
|
#import <Parse/Parse.h>
|
2015-09-04 10:24:55 +08:00
|
|
|
#endif
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
#define kFilteringFactor 0.1
|
|
|
|
#define kRenderingFrequency 60
|
|
|
|
#define kAccelerometerFrequency 100.0 // Hz
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-11-16 08:07:21 +08:00
|
|
|
Error _shell_open(String);
|
2015-11-29 12:18:21 +08:00
|
|
|
void _set_keep_screen_on(bool p_enabled);
|
2015-11-16 08:07:21 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Error _shell_open(String p_uri) {
|
2017-04-09 20:18:49 +08:00
|
|
|
NSString *url = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()];
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]])
|
|
|
|
return ERR_CANT_OPEN;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
printf("opening url %ls\n", p_uri.c_str());
|
2014-02-10 09:10:30 +08:00
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
|
|
|
|
[url release];
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2015-11-29 12:18:21 +08:00
|
|
|
void _set_keep_screen_on(bool p_enabled) {
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:(BOOL)p_enabled];
|
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
@implementation AppDelegate
|
|
|
|
|
2014-12-03 01:02:41 +08:00
|
|
|
@synthesize window;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
extern int gargc;
|
2017-04-09 20:18:49 +08:00
|
|
|
extern char **gargv;
|
|
|
|
extern int iphone_main(int, int, int, char **);
|
2014-02-10 09:10:30 +08:00
|
|
|
extern void iphone_finish();
|
|
|
|
|
2016-11-13 19:11:00 +08:00
|
|
|
CMMotionManager *motionManager;
|
2017-04-09 20:18:49 +08:00
|
|
|
bool motionInitialised;
|
2016-11-13 19:11:00 +08:00
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
static ViewController *mainViewController = nil;
|
|
|
|
+ (ViewController *)getViewController {
|
2014-02-10 09:10:30 +08:00
|
|
|
return mainViewController;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int frame_count = 0;
|
2017-04-09 20:18:49 +08:00
|
|
|
- (void)drawView:(GLView *)view;
|
|
|
|
{
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
switch (frame_count) {
|
2017-04-09 19:22:40 +08:00
|
|
|
case 0: {
|
|
|
|
int backingWidth;
|
|
|
|
int backingHeight;
|
|
|
|
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
|
|
|
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
|
|
|
|
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm.fullscreen = true;
|
|
|
|
vm.width = backingWidth;
|
|
|
|
vm.height = backingHeight;
|
|
|
|
vm.resizable = false;
|
|
|
|
OS::get_singleton()->set_video_mode(vm);
|
|
|
|
|
|
|
|
if (!OS::get_singleton()) {
|
|
|
|
exit(0);
|
|
|
|
};
|
|
|
|
++frame_count;
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
2017-04-09 19:22:40 +08:00
|
|
|
NSString *documentsDirectory = [paths objectAtIndex:0];
|
|
|
|
//NSString *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
|
|
|
|
OSIPhone::get_singleton()->set_data_dir(String::utf8([documentsDirectory UTF8String]));
|
|
|
|
|
|
|
|
NSString *locale_code = [[[NSLocale preferredLanguages] objectAtIndex:0] substringToIndex:2];
|
|
|
|
OSIPhone::get_singleton()->set_locale(String::utf8([locale_code UTF8String]));
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
NSString *uuid;
|
|
|
|
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
|
2017-04-09 19:22:40 +08:00
|
|
|
uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
|
|
|
|
} else {
|
|
|
|
// before iOS 6, so just generate an identifier and store it
|
|
|
|
uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"identiferForVendor"];
|
2017-04-09 20:18:49 +08:00
|
|
|
if (!uuid) {
|
2017-04-09 19:22:40 +08:00
|
|
|
CFUUIDRef cfuuid = CFUUIDCreate(NULL);
|
2017-04-09 20:18:49 +08:00
|
|
|
uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, cfuuid);
|
2017-04-09 19:22:40 +08:00
|
|
|
CFRelease(cfuuid);
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:uuid forKey:@"identifierForVendor"];
|
|
|
|
}
|
2014-04-05 23:39:30 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
OSIPhone::get_singleton()->set_unique_ID(String::utf8([uuid UTF8String]));
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
}; break;
|
2017-04-09 20:18:49 +08:00
|
|
|
/*
|
2017-04-09 19:22:40 +08:00
|
|
|
case 1: {
|
|
|
|
++frame_count;
|
|
|
|
}; break;
|
2014-02-10 09:10:30 +08:00
|
|
|
*/
|
2017-04-09 19:22:40 +08:00
|
|
|
case 1: {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
Main::setup2();
|
|
|
|
++frame_count;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
// this might be necessary before here
|
2017-04-09 20:18:49 +08:00
|
|
|
NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];
|
|
|
|
for (NSString *key in dict) {
|
|
|
|
NSObject *value = [dict objectForKey:key];
|
2017-04-09 19:22:40 +08:00
|
|
|
String ukey = String::utf8([key UTF8String]);
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
// we need a NSObject to Variant conversor
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
if ([value isKindOfClass:[NSString class]]) {
|
2017-04-09 20:18:49 +08:00
|
|
|
NSString *str = (NSString *)value;
|
2017-04-09 19:22:40 +08:00
|
|
|
String uval = String::utf8([str UTF8String]);
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
GlobalConfig::get_singleton()->set("Info.plist/" + ukey, uval);
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
} else if ([value isKindOfClass:[NSNumber class]]) {
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
NSNumber *n = (NSNumber *)value;
|
2017-04-09 19:22:40 +08:00
|
|
|
double dval = [n doubleValue];
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
GlobalConfig::get_singleton()->set("Info.plist/" + ukey, dval);
|
2017-04-09 19:22:40 +08:00
|
|
|
};
|
|
|
|
// do stuff
|
|
|
|
}
|
2015-06-30 22:28:43 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
}; break;
|
2017-04-09 20:18:49 +08:00
|
|
|
/*
|
2017-04-09 19:22:40 +08:00
|
|
|
case 3: {
|
|
|
|
++frame_count;
|
|
|
|
}; break;
|
2014-02-10 09:10:30 +08:00
|
|
|
*/
|
2017-04-09 19:22:40 +08:00
|
|
|
case 2: {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
Main::start();
|
|
|
|
++frame_count;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
}; break; // no fallthrough
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
default: {
|
|
|
|
if (OSIPhone::get_singleton()) {
|
2017-04-09 20:18:49 +08:00
|
|
|
//OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]);
|
2017-04-09 19:22:40 +08:00
|
|
|
if (motionInitialised) {
|
|
|
|
// Just using polling approach for now, we can set this up so it sends data to us in intervals, might be better.
|
|
|
|
// See Apple reference pages for more details:
|
|
|
|
// https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
|
|
|
|
|
|
|
|
// Apple splits our accelerometer date into a gravity and user movement component. We add them back together
|
|
|
|
CMAcceleration gravity = motionManager.deviceMotion.gravity;
|
|
|
|
CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration;
|
|
|
|
|
|
|
|
///@TODO We don't seem to be getting data here, is my device broken or is this code incorrect?
|
|
|
|
CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field;
|
|
|
|
|
|
|
|
///@TODO we can access rotationRate as a CMRotationRate variable (processed date) or CMGyroData (raw data), have to see what works best
|
|
|
|
CMRotationRate rotation = motionManager.deviceMotion.rotationRate;
|
|
|
|
|
|
|
|
// Adjust for screen orientation.
|
|
|
|
// [[UIDevice currentDevice] orientation] changes even if we've fixed our orientation which is not
|
|
|
|
// a good thing when you're trying to get your user to move the screen in all directions and want consistent output
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
///@TODO Using [[UIApplication sharedApplication] statusBarOrientation] is a bit of a hack. Godot obviously knows the orientation so maybe we
|
2017-04-09 19:22:40 +08:00
|
|
|
// can use that instead? (note that left and right seem swapped)
|
|
|
|
|
|
|
|
switch ([[UIApplication sharedApplication] statusBarOrientation]) {
|
|
|
|
case UIDeviceOrientationLandscapeLeft: {
|
|
|
|
OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), (acceleration.x + gravity.x), acceleration.z + gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z);
|
|
|
|
OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z);
|
|
|
|
}; break;
|
|
|
|
case UIDeviceOrientationLandscapeRight: {
|
|
|
|
OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_accelerometer((acceleration.y + gravity.y), -(acceleration.x + gravity.x), acceleration.z + gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_magnetometer(magnetic.y, -magnetic.x, magnetic.z);
|
|
|
|
OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, rotation.z);
|
|
|
|
}; break;
|
|
|
|
case UIDeviceOrientationPortraitUpsideDown: {
|
|
|
|
OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), (acceleration.y + gravity.y), acceleration.z + gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z);
|
|
|
|
OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z);
|
|
|
|
}; break;
|
|
|
|
default: { // assume portrait
|
|
|
|
OSIPhone::get_singleton()->update_gravity(gravity.x, gravity.y, gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
|
|
|
|
OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
|
|
|
|
OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z);
|
|
|
|
}; break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool quit_request = OSIPhone::get_singleton()->iterate();
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
}; break;
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
|
|
|
|
|
|
|
printf("****************** did receive memory warning!\n");
|
2014-05-14 12:22:15 +08:00
|
|
|
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_MEMORY_WARNING);
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
- (void)applicationDidFinishLaunching:(UIApplication *)application {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
printf("**************** app delegate init\n");
|
|
|
|
CGRect rect = [[UIScreen mainScreen] bounds];
|
|
|
|
|
2014-02-19 22:57:14 +08:00
|
|
|
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
|
2014-02-10 09:10:30 +08:00
|
|
|
// disable idle timer
|
2015-11-29 12:18:21 +08:00
|
|
|
//application.idleTimerDisabled = YES;
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
//Create a full-screen window
|
|
|
|
window = [[UIWindow alloc] initWithFrame:rect];
|
|
|
|
//window.autoresizesSubviews = YES;
|
|
|
|
//[window setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
|
|
|
|
|
|
|
|
//Create the OpenGL ES view and add it to the window
|
|
|
|
GLView *glView = [[GLView alloc] initWithFrame:rect];
|
|
|
|
printf("glview is %p\n", glView);
|
|
|
|
//[window addSubview:glView];
|
|
|
|
glView.delegate = self;
|
|
|
|
//glView.autoresizesSubviews = YES;
|
|
|
|
//[glView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
|
|
|
|
|
2017-01-07 16:33:11 +08:00
|
|
|
int backingWidth;
|
|
|
|
int backingHeight;
|
|
|
|
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
|
|
|
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2017-01-07 16:33:11 +08:00
|
|
|
iphone_main(backingWidth, backingHeight, gargc, gargv);
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
view_controller = [[ViewController alloc] init];
|
|
|
|
view_controller.view = glView;
|
|
|
|
window.rootViewController = view_controller;
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
_set_keep_screen_on(bool(GLOBAL_DEF("display/keep_screen_on", true)) ? YES : NO);
|
|
|
|
glView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink", true)) ? YES : NO;
|
2015-10-23 08:31:09 +08:00
|
|
|
printf("cadisaplylink: %d", glView.useCADisplayLink);
|
2014-02-10 09:10:30 +08:00
|
|
|
glView.animationInterval = 1.0 / kRenderingFrequency;
|
|
|
|
[glView startAnimation];
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
//Show the window
|
|
|
|
[window makeKeyAndVisible];
|
|
|
|
|
|
|
|
//Configure and start accelerometer
|
2016-11-13 19:11:00 +08:00
|
|
|
if (!motionInitialised) {
|
|
|
|
motionManager = [[CMMotionManager alloc] init];
|
|
|
|
if (motionManager.deviceMotionAvailable) {
|
2017-04-09 20:18:49 +08:00
|
|
|
motionManager.deviceMotionUpdateInterval = 1.0 / 70.0;
|
2017-04-09 19:22:40 +08:00
|
|
|
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical];
|
2016-11-13 19:11:00 +08:00
|
|
|
motionInitialised = YES;
|
|
|
|
};
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
//OSIPhone::screen_width = rect.size.width - rect.origin.x;
|
|
|
|
//OSIPhone::screen_height = rect.size.height - rect.origin.y;
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2014-07-02 11:09:36 +08:00
|
|
|
mainViewController = view_controller;
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2014-07-02 11:09:36 +08:00
|
|
|
#ifdef MODULE_GAME_ANALYTICS_ENABLED
|
2017-04-09 19:22:40 +08:00
|
|
|
printf("********************* didFinishLaunchingWithOptions\n");
|
|
|
|
if (!GlobalConfig::get_singleton()->has("mobileapptracker/advertiser_id")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!GlobalConfig::get_singleton()->has("mobileapptracker/conversion_key")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
String adid = GLOBAL_DEF("mobileapptracker/advertiser_id", "");
|
|
|
|
String convkey = GLOBAL_DEF("mobileapptracker/conversion_key", "");
|
2017-04-09 19:22:40 +08:00
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
NSString *advertiser_id = [NSString stringWithUTF8String:adid.utf8().get_data()];
|
|
|
|
NSString *conversion_key = [NSString stringWithUTF8String:convkey.utf8().get_data()];
|
2017-04-09 19:22:40 +08:00
|
|
|
|
|
|
|
// Account Configuration info - must be set
|
|
|
|
[MobileAppTracker initializeWithMATAdvertiserId:advertiser_id MATConversionKey:conversion_key];
|
|
|
|
|
|
|
|
// Used to pass us the IFA, enables highly accurate 1-to-1 attribution.
|
|
|
|
// Required for many advertising networks.
|
|
|
|
[MobileAppTracker setAppleAdvertisingIdentifier:[[ASIdentifierManager sharedManager] advertisingIdentifier]
|
2017-04-09 20:18:49 +08:00
|
|
|
advertisingTrackingEnabled:[[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]];
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2014-07-02 11:09:36 +08:00
|
|
|
#endif
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
printf("********************* will terminate\n");
|
2016-11-13 19:11:00 +08:00
|
|
|
|
|
|
|
if (motionInitialised) {
|
|
|
|
///@TODO is this the right place to clean this up?
|
2017-01-07 16:33:11 +08:00
|
|
|
[motionManager stopDeviceMotionUpdates];
|
|
|
|
[motionManager release];
|
|
|
|
motionManager = nil;
|
2017-04-09 20:18:49 +08:00
|
|
|
motionInitialised = NO;
|
2016-11-13 19:11:00 +08:00
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
iphone_finish();
|
|
|
|
};
|
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
2014-02-10 09:10:30 +08:00
|
|
|
printf("********************* did enter background\n");
|
2016-11-13 19:11:00 +08:00
|
|
|
///@TODO maybe add pause motionManager? and where would we unpause it?
|
|
|
|
|
2014-10-07 12:31:49 +08:00
|
|
|
if (OS::get_singleton()->get_main_loop())
|
|
|
|
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
2017-04-09 19:22:40 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
[view_controller.view stopAnimation];
|
2014-12-03 01:02:41 +08:00
|
|
|
if (OS::get_singleton()->native_video_is_playing()) {
|
|
|
|
OSIPhone::get_singleton()->native_video_focus_out();
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
2014-02-10 09:10:30 +08:00
|
|
|
printf("********************* did enter foreground\n");
|
2014-09-03 10:13:40 +08:00
|
|
|
//OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
2014-02-10 09:10:30 +08:00
|
|
|
[view_controller.view startAnimation];
|
|
|
|
}
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application {
|
2014-02-10 09:10:30 +08:00
|
|
|
printf("********************* will resign active\n");
|
2014-09-03 10:13:40 +08:00
|
|
|
//OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
2014-02-10 09:10:30 +08:00
|
|
|
[view_controller.view stopAnimation]; // FIXME: pause seems to be recommended elsewhere
|
|
|
|
}
|
|
|
|
|
2017-04-09 20:18:49 +08:00
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
2014-02-10 09:10:30 +08:00
|
|
|
printf("********************* did become active\n");
|
2014-07-02 11:09:36 +08:00
|
|
|
#ifdef MODULE_GAME_ANALYTICS_ENABLED
|
2017-04-09 19:22:40 +08:00
|
|
|
printf("********************* mobile app tracker found\n");
|
2014-07-02 11:09:36 +08:00
|
|
|
[MobileAppTracker measureSession];
|
|
|
|
#endif
|
2014-10-07 12:31:49 +08:00
|
|
|
if (OS::get_singleton()->get_main_loop())
|
|
|
|
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
2017-04-09 19:22:40 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
[view_controller.view startAnimation]; // FIXME: resume seems to be recommended elsewhere
|
2014-11-27 01:24:13 +08:00
|
|
|
if (OSIPhone::get_singleton()->native_video_is_playing()) {
|
|
|
|
OSIPhone::get_singleton()->native_video_unpause();
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
|
2014-04-10 11:18:27 +08:00
|
|
|
#ifdef MODULE_FACEBOOKSCORER_IOS_ENABLED
|
2014-02-10 09:10:30 +08:00
|
|
|
return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// For 4.2+ support
|
|
|
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
|
2015-09-04 10:24:55 +08:00
|
|
|
#ifdef MODULE_PARSE_ENABLED
|
|
|
|
NSLog(@"Handling application openURL");
|
2017-04-09 20:18:49 +08:00
|
|
|
return [[FBSDKApplicationDelegate sharedInstance]
|
|
|
|
application:application
|
|
|
|
openURL:url
|
|
|
|
sourceApplication:sourceApplication
|
|
|
|
annotation:annotation];
|
2015-09-04 10:24:55 +08:00
|
|
|
#endif
|
|
|
|
|
2014-04-10 11:18:27 +08:00
|
|
|
#ifdef MODULE_FACEBOOKSCORER_IOS_ENABLED
|
2014-02-10 09:10:30 +08:00
|
|
|
return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-04 10:24:55 +08:00
|
|
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
|
#ifdef MODULE_PARSE_ENABLED
|
|
|
|
// Store the deviceToken in the current installation and save it to Parse.
|
|
|
|
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
|
|
|
|
//NSString* token = [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding];
|
|
|
|
NSLog(@"Device Token : %@ ", deviceToken);
|
|
|
|
[currentInstallation setDeviceTokenFromData:deviceToken];
|
|
|
|
[currentInstallation saveInBackground];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
|
|
|
#ifdef MODULE_PARSE_ENABLED
|
|
|
|
[PFPush handlePush:userInfo];
|
|
|
|
NSDictionary *aps = [userInfo objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
2016-04-03 02:26:12 +08:00
|
|
|
|
2015-09-04 10:24:55 +08:00
|
|
|
NSLog(@"Push Notification Payload (app active) %@", aps);
|
|
|
|
[defaults setObject:aps forKey:@"notificationInfo"];
|
|
|
|
[defaults synchronize];
|
|
|
|
if (application.applicationState == UIApplicationStateInactive) {
|
|
|
|
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:22:40 +08:00
|
|
|
- (void)dealloc {
|
2014-02-10 09:10:30 +08:00
|
|
|
[window release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|