checking player prefs from unity in xcode
- by user313100
I made a simple scene that has some GUI buttons in Unity. When you press a button it will set a player preference to 1. I have a button for facebook, twitter and a store. In XCode, when the value hits 1, it switches to a new window with facebook, twitter or the store. My problem is that when I try and retrieve the player preferences in XCode, they always come up as null. To compound my confusion, my code seems to respond to the switch to 1 and it switches to the new window when the value hits 1. Any ideas why it manages to switch to the other window and why I am getting null values?
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
printf_console("-> applicationDidFinishLaunching()\n");
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setInteger:0 forKey:@"Store"];
[userDefaults setInteger:0 forKey:@"Facebook"];
[userDefaults setInteger:0 forKey:@"Twitter"];
_storeWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_facebookWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_twitterWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
viewControllerSK = [[SKViewController alloc]initWithNibName:@"SKViewController" bundle:nil];
viewControllerFacebook = [[xutils_exampleViewController alloc]initWithNibName:@"FacebookViewController" bundle:nil];
viewControllerTwitter = [[xutils_exampleViewController2 alloc]initWithNibName:@"TwitterViewController" bundle:nil];
[_storeWindow addSubview:viewControllerSK.view];
[_facebookWindow addSubview:viewControllerFacebook.view];
[_twitterWindow addSubview:viewControllerTwitter.view];
[SKStoreManager sharedManager];
[self startUnity:application];
}
- (void) applicationDidBecomeActive:(UIApplication*)application
{
printf_console("-> applicationDidBecomeActive()\n");
if (gDidResignActive == true)
{
UnitySetAudioSessionActive(true);
UnityPause(false);
}
gDidResignActive = false;
[self newTimer];
}
- (void) applicationWillResignActive:(UIApplication*)application
{
printf_console("-> applicationDidResignActive()\n");
UnitySetAudioSessionActive(false);
UnityPause(true);
gDidResignActive = true;
}
- (void) applicationDidReceiveMemoryWarning:(UIApplication*)application
{
printf_console("WARNING -> applicationDidReceiveMemoryWarning()\n");
}
- (void) applicationWillTerminate:(UIApplication*)application
{
printf_console("-> applicationWillTerminate()\n");
UnityCleanup();
}
-(void)newTimer
{
NSTimer *theTimer = [self getTimer];
[theTimer retain];
[[NSRunLoop currentRunLoop] addTimer: theTimer forMode: NSDefaultRunLoopMode];
}
-(NSTimer *)getTimer
{
NSTimer *theTimer;
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector: @selector(onLoop) userInfo:nil repeats:YES];
return [theTimer autorelease];
}
-(void)onLoop
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//NSLog(@"FB: %@", [userDefaults integerForKey:@"Facebook"]);
if ([userDefaults integerForKey:@"Store"] != 1 && [userDefaults integerForKey:@"Facebook"] != 1 && [userDefaults integerForKey:@"Twitter"] != 1)
{
UnityPause(FALSE);
_window.hidden = NO;
_storeWindow.hidden = YES;
_facebookWindow.hidden = YES;
_twitterWindow.hidden = YES;
[_window makeKeyWindow];
}
if ([userDefaults integerForKey:@"Store"] == 1)
{
UnityPause(TRUE);
_storeWindow.hidden = NO;
_window.hidden = YES;
[_storeWindow makeKeyWindow];
}
if ([userDefaults integerForKey:@"Facebook"] == 1)
{
UnityPause(TRUE);
_facebookWindow.hidden = NO;
_window.hidden = YES;
[_facebookWindow makeKeyWindow];
}
if ([userDefaults integerForKey:@"Twitter"] == 1)
{
UnityPause(TRUE);
_twitterWindow.hidden = NO;
_window.hidden = YES;
[_twitterWindow makeKeyWindow];
}
}
-(void) dealloc
{
DestroySurface(&_surface);
[_context release];
_context = nil;
[_window release];
[_storeWindow release];
[_facebookWindow release];
[_twitterWindow release];
[viewControllerSK release];
[viewControllerFacebook release];
[viewControllerTwitter release];
[super dealloc];
}