project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m
branchios-develop
changeset 12872 00215a7ec5f5
parent 11309 402baa6d4f64
equal deleted inserted replaced
12871:2c06b1120749 12872:00215a7ec5f5
    22 #import "Appirater.h"
    22 #import "Appirater.h"
    23 
    23 
    24 @implementation SDLUIKitDelegate (customDelegate)
    24 @implementation SDLUIKitDelegate (customDelegate)
    25 
    25 
    26 // hijack the the SDL_UIKitAppDelegate to use the UIApplicationDelegate we implement here
    26 // hijack the the SDL_UIKitAppDelegate to use the UIApplicationDelegate we implement here
    27 +(NSString *)getAppDelegateClassName {
    27 + (NSString *)getAppDelegateClassName {
    28     return @"HedgewarsAppDelegate";
    28     return @"HedgewarsAppDelegate";
    29 }
    29 }
    30 
    30 
    31 @end
    31 @end
    32 
    32 
    33 @implementation HedgewarsAppDelegate
    33 @implementation HedgewarsAppDelegate
    34 @synthesize mainViewController, uiwindow;
    34 @synthesize mainViewController, uiwindow;
    35 
    35 
    36 #pragma mark -
    36 #pragma mark -
    37 #pragma mark AppDelegate methods
    37 #pragma mark AppDelegate methods
    38 -(id) init {
    38 - (id)init {
    39     if ((self = [super init])) {
    39     if ((self = [super init])) {
    40         mainViewController = nil;
    40         mainViewController = nil;
    41         uiwindow = nil;
    41         uiwindow = nil;
    42     }
    42     }
    43     return self;
    43     return self;
    44 }
    44 }
    45 
    45 
    46 -(void) dealloc {
       
    47     [mainViewController release];
       
    48     [uiwindow release];
       
    49     [super dealloc];
       
    50 }
       
    51 
    46 
    52 // override the direct execution of SDL_main to allow us to implement our own frontend
    47 // override the direct execution of SDL_main to allow us to implement our own frontend
    53 -(void) postFinishLaunch
    48 - (void)postFinishLaunch
    54 {
    49 {
    55     // Setup Appirater
    50     // Setup Appirater
    56     [Appirater setAppId:@"391234866"];
    51     [Appirater setAppId:@"391234866"];
    57     [Appirater setDaysUntilPrompt:3];
    52     [Appirater setDaysUntilPrompt:3];
    58     [Appirater setUsesUntilPrompt:5];
    53     [Appirater setUsesUntilPrompt:5];
    68     self.uiwindow.backgroundColor = [UIColor blackColor];
    63     self.uiwindow.backgroundColor = [UIColor blackColor];
    69 
    64 
    70     NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone");
    65     NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone");
    71     self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil];
    66     self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil];
    72     self.uiwindow.rootViewController = self.mainViewController;
    67     self.uiwindow.rootViewController = self.mainViewController;
    73     [self.mainViewController release];
       
    74 
    68 
    75     [self.uiwindow makeKeyAndVisible];
    69     [self.uiwindow makeKeyAndVisible];
    76 }
    70 }
    77 
    71 
    78 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
    72 - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    79     [HWUtils releaseCache];
    73     [HWUtils releaseCache];
    80     // don't stop music if it is playing
    74     // don't stop music if it is playing
    81     if ([HWUtils isGameLaunched]) {
    75     if ([HWUtils isGameLaunched]) {
    82         [[AudioManagerController mainManager] didReceiveMemoryWarning];
    76         [[AudioManagerController mainManager] didReceiveMemoryWarning];
    83         HW_memoryWarningCallback();
    77         HW_memoryWarningCallback();
    85     MSG_MEMCLEAN();
    79     MSG_MEMCLEAN();
    86     // don't clean mainMenuViewController here!!!
    80     // don't clean mainMenuViewController here!!!
    87 }
    81 }
    88 
    82 
    89 // true multitasking with SDL works only on 4.2 and above; we close the game to avoid a black screen at return
    83 // true multitasking with SDL works only on 4.2 and above; we close the game to avoid a black screen at return
    90 -(void) applicationWillResignActive:(UIApplication *)application {
    84 - (void)applicationWillResignActive:(UIApplication *)application {
    91     if ([HWUtils isGameLaunched] && [[[UIDevice currentDevice] systemVersion] floatValue] < 4.2f)
    85     if ([HWUtils isGameLaunched] && [[[UIDevice currentDevice] systemVersion] floatValue] < 4.2f)
    92         HW_terminate(NO);
    86         HW_terminate(NO);
    93 
    87 
    94     [super applicationWillResignActive:application];
    88     [super applicationWillResignActive:application];
    95 }
    89 }