Changeset 26 for trunk/Classes/SDL/src/video/uikit/SDL_uikitappdelegate.mm
- Timestamp:
- 2010-05-28 07:39:52 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Classes/SDL/src/video/uikit/SDL_uikitappdelegate.mm
r23 r26 23 23 #import "SDL_uikitappdelegate.h" 24 24 #import "SDL_uikitopenglview.h" 25 #import <CommonCrypto/CommonDigest.h> 25 26 26 27 extern "C" … … 30 31 }; 31 32 32 #import "FlurryAPI.h" 33 #import "OpenFeint.h" 33 //#import "FlurryAPI.h" 34 #ifndef DISABLE_OPENFEINT 35 #import "OpenFeint.h" 36 #endif 34 37 35 38 #ifdef main 36 39 #undef main 37 40 #endif 41 42 extern "C" unsigned char gFlippedGL, gInitializedGL; 43 unsigned char gFlippedGL = 0; 44 extern UIView *gLandscapeView; 45 extern bool gRedraw; 38 46 39 47 extern "C" int SDL_main(int argc, char *argv[]); … … 104 112 exit(exit_status); 105 113 } 106 114 /* 107 115 void uncaughtExceptionHandler(NSException *exception) { 108 116 [FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception]; 109 117 } 110 118 */ 111 119 - (void)applicationDidFinishLaunching:(UIApplication *)application { 112 120 113 [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight]; 121 [NSThread sleepForTimeInterval:1]; 122 123 124 UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; 125 126 127 if (!UIDeviceOrientationIsLandscape(deviceOrientation)) 128 [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight]; 129 130 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 131 [[NSNotificationCenter defaultCenter] addObserver:self 132 selector:@selector(didRotate:) 133 name:UIDeviceOrientationDidChangeNotification object:nil]; 134 114 135 115 136 /* Set working directory to resource path */ … … 141 162 */ 142 163 164 #ifndef __IPAD__ 165 // AdMob campaign tracking 166 // [self performSelectorInBackground:@selector(reportAppOpenToAdMob) withObject:nil]; 167 #endif 168 143 169 // KP: using a selector gets around the "failed to launch application in time" if the startup code takes too long 144 170 // This is easy to see if running with Valgrind 145 [self performSelector:@selector(runSDLMain:) withObject:@"" afterDelay: 0.1f]; 146 171 [self performSelector:@selector(runSDLMain:) withObject:@"" afterDelay: 0.2f]; 147 172 } 148 173 149 174 - (void)applicationWillTerminate:(UIApplication *)application { 175 176 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 150 177 151 178 SDL_SendQuit(); … … 172 199 - (void)applicationDidBecomeActive 173 200 { 201 #ifndef DISABLE_OPENFEINT 174 202 [OpenFeint applicationDidBecomeActive]; 203 #endif 175 204 } 176 205 177 206 - (void)applicationWillResignActive 178 207 { 208 #ifndef DISABLE_OPENFEINT 179 209 [OpenFeint applicationWillResignActive]; 210 #endif 211 } 212 /* 213 - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation 214 { 215 UIDeviceOrientation ori = [UIDevice currentDevice].orientation; 216 [OpenFeint setDashboardOrientation:orientation] 217 } 218 */ 219 220 -(void)didRotate:(NSNotification *)theNotification { 221 UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; 222 223 224 UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; 225 226 if (!UIInterfaceOrientationIsLandscape(interfaceOrientation) && gInitializedGL == false) 227 { 228 interfaceOrientation = UIInterfaceOrientationLandscapeRight; 229 } 230 231 // check if we flipped upside down 232 if (deviceOrientation == UIDeviceOrientationLandscapeLeft && interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 233 interfaceOrientation = UIInterfaceOrientationLandscapeRight; 234 else if (deviceOrientation == UIDeviceOrientationLandscapeRight && interfaceOrientation == UIInterfaceOrientationLandscapeRight) 235 interfaceOrientation = UIInterfaceOrientationLandscapeLeft; 236 237 bool changed = false; 238 if (gInitializedGL == false) 239 changed = true; 240 241 if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 242 { 243 if (gFlippedGL == false) 244 changed = true; 245 gFlippedGL = true; 246 } 247 else 248 { 249 if (gFlippedGL == true) 250 changed = true; 251 gFlippedGL = false; 252 } 253 254 if (changed == false) 255 return; 256 257 [[UIApplication sharedApplication] setStatusBarOrientation: interfaceOrientation]; 258 #ifndef DISABLE_OPENFEINT 259 [OpenFeint setDashboardOrientation: interfaceOrientation]; 260 #endif 261 262 if (!gInitializedGL) 263 return; 264 265 glMatrixMode(GL_MODELVIEW); 266 glLoadIdentity(); 267 #ifdef __IPAD__ 268 glViewport(0, 0, 768, 1024); 269 if (gFlippedGL) 270 glRotatef(90, 0, 0, 1); 271 else 272 glRotatef(-90, 0, 0, 1); 273 glOrthof(0.0, (GLfloat) 1024, (GLfloat) 768, 0.0, 0, 100.0f); 274 #else 275 glViewport(0, 0, 320, 480); 276 if (gFlippedGL) 277 glRotatef(90, 0, 0, 1); 278 else 279 glRotatef(-90, 0, 0, 1); 280 glOrthof(0.0, (GLfloat) 480, (GLfloat) 320, 0.0, 0, 100.0f); 281 #endif 282 gRedraw = true; 283 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 284 285 CGAffineTransform tr = CGAffineTransformIdentity; // get current transform (portrait) 286 if (gFlippedGL) 287 tr = CGAffineTransformRotate(tr, -(M_PI / 2.0)); // rotate 90 degrees to go landscape 288 else 289 tr = CGAffineTransformRotate(tr, (M_PI / 2.0)); // rotate 90 degrees to go landscape 290 291 gLandscapeView.transform = tr; // set current transform (landscape) 292 293 } 294 295 296 // AdMob campaign tracking 297 298 // This method requires adding #import <CommonCrypto/CommonDigest.h> to your source file. 299 - (NSString *)hashedISU { 300 NSString *result = nil; 301 NSString *isu = [UIDevice currentDevice].uniqueIdentifier; 302 303 if(isu) { 304 unsigned char digest[16]; 305 NSData *data = [isu dataUsingEncoding:NSASCIIStringEncoding]; 306 CC_MD5([data bytes], [data length], digest); 307 308 result = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 309 digest[0], digest[1], 310 digest[2], digest[3], 311 digest[4], digest[5], 312 digest[6], digest[7], 313 digest[8], digest[9], 314 digest[10], digest[11], 315 digest[12], digest[13], 316 digest[14], digest[15]]; 317 result = [result uppercaseString]; 318 } 319 return result; 320 } 321 322 - (void)reportAppOpenToAdMob { 323 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // we're in a new thread here, so we need our own autorelease pool 324 // Have we already reported an app open? 325 NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 326 NSUserDomainMask, YES) objectAtIndex:0]; 327 NSString *appOpenPath = [documentsDirectory stringByAppendingPathComponent:@"admob_app_open"]; 328 NSFileManager *fileManager = [NSFileManager defaultManager]; 329 if(![fileManager fileExistsAtPath:appOpenPath]) { 330 // Not yet reported -- report now 331 NSString *appOpenEndpoint = [NSString stringWithFormat:@"http://a.admob.com/f0?isu=%@&md5=1&app_id=%@", 332 [self hashedISU], @"340691963"]; 333 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:appOpenEndpoint]]; 334 NSURLResponse *response; 335 NSError *error; 336 NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 337 if((!error) && ([(NSHTTPURLResponse *)response statusCode] == 200) && ([responseData length] > 0)) { 338 [fileManager createFileAtPath:appOpenPath contents:nil attributes:nil]; // successful report, mark it as such 339 } 340 } 341 [pool release]; 180 342 } 181 343
Note: See TracChangeset
for help on using the changeset viewer.