game center not working on ipod/iphone - iphone

Hi all
Working on a universal build for an iphone/ipod/ipad app. I was trying to get game center working within this app. I now have the game center working on the ipad but for some reason it still wont work on the ipod/iphone and i have no idea why.
highScoreVC=[[UIViewController alloc] init];
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:highScoreVC.view];
[highScoreVC presentModalViewController:leaderboardController animated: YES];
}
this is my code for displaying the leaderboard and it does work everytime for ipad but as i said not for other devices. the code is still being called the same as for ipad so i have no clue why it is not displaying. any ideas why this would be? cheers

As far as I'm concerned, [GKLeaderboardViewController init] will return nil if the device is not authenticated with Game Center by that point. Are you sure you are correctly authenticated on the devices causing problems?

I suspect there may be some issues with how your UIKit items for Game Center are being displayed if they are working fine on the iPad but not iPhone/iPod. I experienced similar sounding issues when converting an app to universal.
If you create a new standalone iPhone/iPod project just for testing does game center display fine?

ok i got it working in the end.
cocos2d 0.99.5 has indeed made some changes that to how this works. the following code displays the leaderboard correctly
-(UIViewController*) getRootViewController{
return (UIViewController*)([(BubbleDreamsAppDelegate*) [[UIApplication sharedApplication] delegate] viewController]);
}
and then
highScoreVC = [self getRootViewController];
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[highScoreVC presentModalViewController:leaderboardController animated: YES];
}
hope this helps anyone that gets stuck with same problem

Related

Game Center with iOS 5 SDK - leaderboardDelegate = self not working

I am still using iOS 5 SDK and Xcode 4.2 (Snow Leopard). I am adding Game Center to my game and while it passed authentication I get an ARC error whenever I try to show a leaderboard with this code (from Apple):
- (void) showLeaderboard: (NSString*) leaderboardID
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
**leaderboardController.leaderboardDelegate = self;**
leaderboardController.timeScope = GKLeaderboardTimeScopeToday;
leaderboardController.category = leaderboardID;
[self presentViewController: leaderboardController animated: YES completion:nil];
}
}
I get this error:
Passing "ViewController *const__strong' to parameter of incompatible type 'id <GKLeaderboardViewControllerDelegate>"
Is there any other solution than using iOS 6 SDK on lion?
Thanks!
Ah,
Found a similar problem, using id(self) fixed it;
Handling app delegates and switching between views
Should I delete this question>

admob click after return it wrong layout

I use cocos2d combined with AdMob , nomarl my app work great, but after hit the advertising and return the game, it wrong layout, my game is landscape!
Things changes after AdMob is involved. AdMob has a AD type "movie". After clicking the ad, it popups a full screen mode, and play a movie, and then back to the game. The game changes, originally, it is landscape mode, and after back from ad, it seems to be portrait mode, and the game is scaled, everything looks bad. I have tried to update the view controller / CCDirector after back from ad, but it doesn't work.
A workaround found: just rotate the device to the counterpart landscape mode and everything goes well again.
Just wonder if there is any way to prevent telling customers rotate it manually?
Have you encountered this before?
_viewController = [[UIViewController alloc] init];
_viewController.view = [[CCDirector sharedDirector] openGLView];
_admobView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
_admobView.adUnitID = ADMOB_PUBLISHER_ID;
_admobView.delegate = self;
GADRequest *request = [GADRequest request];
request.testing = YES;
[_admobView setRootViewController:_viewController];
[_admobView loadRequest:request];
[_viewController.view addSubview:_admobView];
I had a similar issue before, and the cause was that I created a new UIViewController and set it as rootViewController for AdMob view - just like what you are doing:
_viewController = [[UIViewController alloc] init];
_viewController.view = [[CCDirector sharedDirector] openGLView];
...
[_admobView setRootViewController:_viewController];
This leads to layout problems when returning from some kinds of advertisement. What I am doing now in my app is like:
adMobView.rootViewController = [RootViewController sharedInstance];
[[[CCDirector sharedDirector] openGLView] addSubview:adMobView];
where [RootViewController sharedInstance] is a class method which returns the only instance of RootViewController in the app. For details please refer to my answer to another question: https://stackoverflow.com/a/10222956/1241690
(For cocos2d 2.x, the second line should be:
[[[CCDirector sharedDirector] view] addSubview:adMobView];
)

UIImageViewController cameraDevice isn't used each time the camera opens

I want my app to only use the front facing camera. So I've implemented the following code.
if ([UIImagePickerControllerisCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
self.imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
This works the first time I open up the camera (it is using the front facing camera). But if I cancel the photo and then re-enter into the camera it is using the rear facing camera.
With each cancel / re-enter into camera it switches between front and rear cameras...
Is there something I am missing?
Tr this code .I used this code and it is working fine .Use this code either in button action or viewwillappear or viewdidload and dismiss the camera view properly
imgPicker =[[UIImagePickerController alloc] init];
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imgPicker.cameraDevice=UIImagePickerControllerCameraDeviceFront;
imgPicker.showsCameraControls = YES;
imgPicker.allowsEditing = YES;
imgPicker.delegate=self;
[self presentViewController:imgPicker
animated:NO completion:nil];
I was having the same problem and resolved the issue in my case by including autorelease on the call to allocate the UIImagePickerController as shown here
UIImagePickerController *cameraUI = [[[UIImagePickerController alloc] init] autorelease];

iPhone GameCenter won't showAchievments

So my problem is that after integrating gamecenter nicely into my iphone app, it won't show the achievements list!
The integration was a success I think because when I use the submitAchievement method, I do unlock achievements on the list. But I must look at the list from the GameCenter App on the iPhone, not within my own app as it doesn't work.
ikuragames first help me get the code right (thx you !!) but it still doesn't work ! :(
-(void)showAchievments
{
//NSLog(#"showAchievments");
GKAchievementViewController *achievements = [GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[(EAGLView *)self.view achievmentsWillAppear];
[self presentModalViewController:achievements animated:YES];
}
}
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
//NSLog(#"achievementViewControllerDidFinish");
[glView achievmentsWillDisappear];
[self dismissModalViewControllerAnimated:YES];
}
On debug mode, I can clearly see that each line or code are "processed" and not error whatsoever is displayed. BUT, nothing appears on my screen :(
Can you please help me ? (here is some doc.)
I found the answer.
Turned out that the view controller I was sending showAchievments to was not the view controller I wanted.
I was doing something like:
[[myViewController sharedInstance] showAchievments];
But the sharedInstance method returned a brand-new, vanilla-initialised myViewController, and not the one I was already using.
Now it works perfectly, I hope this will help someone in the future.

FBlogin dialog box orientation problem

I'm facing a very silly problem and its really hard to resolve for me.
The fblogindialog box that i'm using in my application, appearing in portrait mode always.. But my whole application is in landscape mode.. the main thing is that the keyboard appears landscape and the web view in wich the login appears has the orientation which just suits the landscape mode (means the username and pwd txt boxes are that much wide so that if we rotate the device it would just fit into the landscape mode).
I tried every thing i looked for the status bar orientaition as well. its really frustrating. i'm using a button named post and on the click of this button i written the following code:
AppDelegate_iPhone *appDelegate =(AppDelegate_iPhone *)[[UIApplication sharedApplication]delegate];
if (appDelegate._session == nil)
{
appDelegate._session = [FBSession sessionForApplication:_APP_KEY secret:_SECRET_KEY delegate:self];
}
if(self.loginDialog == NULL || ![appDelegate._session resume])
{
self.loginDialog = [[[FBLoginDialog alloc] init] autorelease];
loginDialog.delegate = self;
[self.loginDialog show];
//self.loginDialog.frame = CGRectMake(0, 0, 480, 320);
[self.view addSubview:loginDialog];
}
here is the screen shot link-- http://i.stack.imgur.com/X4UHi.png
Please help me guys..
Thks very much .
finally i used new facebook sdk to solve this problem. and used the graph apis . A sample which explain all of this is --
https://github.com/reallylongaddress/iPhone-Facebook-Graph-API
and very helpful indeed.
Thanks