Game center unavailable (player is not signed in ) - objective-c

I am integrating game center on cocos2d project.
GKLeaderboardViewController* leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil){
NSLog(#"view make");
leaderboardController.leaderboardDelegate = self;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.category = #"myGameBoard";
[[CCDirector sharedDirector] presentViewController: leaderboardController animated: YES completion:nil];
show popup
Game Center unavailable
Player is not signed in
and no leaderboard appeared.
My Conditions are
1)testuser looks successfully loginnd
this message appeared on screen.
Welcome back testuser
*** sandbox ***
2)then this message appeared
Game Center unavailable
Player is not signed in
3)App upload is ready and pass the validate on organizer
4)app version on itunes connect and local is the same 1.00
5)Bundle Idenfier on itunes connect and local is the same
6)leaderboardController.category name 'myGameBoard' is correctly set.
is there any other point I need to investigate??

I solved this problem for TEST MODE in this way:
Go to Game Center App
Tab Friends
Click Setting
at the end of the screen: SANDBOX and LOGGING MUST BE ON MODE
I hope that it works for everyone

I solved this issue by ensuring the local user was authenticated and logged in:
- (void) authenticateLocalUser
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (![localPlayer isAuthenticated])
{
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error && viewcontroller)
{
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
UIViewController *currentViewController = [[appDelegate window] rootViewController];
[currentViewController presentViewController:viewcontroller animated:YES completion:nil];
}
})];
}
}

Related

Setting object to nil iOS7 vs iOS8

WI have an iPad kiosk app that displays videos on an external monitor connected to the iPad via HDMI. I have a viewController that manages the view on the external monitor. When I am done playing back a video I nil out the MPMoviePlayerController instance. In iOS7 this works fine, but in iOS8 I get a hard crash after setting the moviePlayer to nil.
- (void)removeMoviePlayer {
[self.moviePlayerController.view removeFromSuperview];
[self removeMovieNotificationHandlers];
self.moviePlayerController = nil;}
With Zombies enabled I get a message in the debugger:
[MPAVController release]: message sent to deallocated instance
Again, this crash does not happen when the app runs under iOS7. What has changed that is causing this crash?
After a couple days of trial and error I discovered that when trying to nil out the MPMoviePlayerController instance when the MPMoviePlayerPlaybackState was MPMoviePlaybackStatePaused, the app would crash. When a video reaches the end, the MPMoviePlayerController sends a MPMoviePlaybackDidFinish notification that reports the playback state as MPMoviePlaybackStatePaused. The fix was to test for playback state and if paused call [MPMoviePlayerController stop]. That changes the MPMoviePlaybackState to MPMoviePlaybackStateStopped, and you can then nil out the instance without a crash.
This crash did not happen before iOS 8. Code below:
-(void)moviePlayBackDidFinish:(NSNotification *)notification {
[self stopVideo:notification];
}
- (void)stopVideo:(NSNotification *)notification {
if (self.moviePlayerController) {
if (self.moviePlayerController.playbackState == MPMoviePlaybackStatePlaying || self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused) {
[self.moviePlayerController stop];
}
[self cleanUpVideo];
}
}
- (void)cleanUpVideo {
[self killProgressTimer];
[UIView animateWithDuration:1.0f animations:^{
self.closedCaptionLabel.alpha = 0.0f;
self.moviePlayerController.view.alpha = 0.0f;
self.backgroundImageView.alpha = 1.0f;
} completion:^(BOOL finished) {
[self removeMoviePlayer];
[self resetClosedCaptions];
[self.delegate videoDidStop];
}];
}
- (void)removeMoviePlayer {
[self.moviePlayerController.view removeFromSuperview];
[self removeMovieNotificationHandlers];
self.moviePlayerController = nil;
}

Facebook SDK, Login Error

I'm setting up my app so that users can login with Facebook. I've loaded the Facebook SDK, but for some reason I get this error in the console when I try to "log in" to Facebook:
FBSDKLog: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x10906da90 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ErrorSessionKey=, expirationDate: 2014-01-02 03:26:48 +0000, refreshDate: 2013-11-03 06:19:26 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions.
Does anyone know why? Take a look at the code below. I feel like it has something to do with my ShowLoginView method (I'm attempting to open the SSLoginViewcontroller Xib on top of an existing Storyboard). I was able to log into Facebook fine before I started messing with this method... Help :)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.mainViewController = [[SSViewController alloc]
initWithNibName:#"SSViewController" bundle:nil];
self.navController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// Yes, so just open the session (this won't display any UX).
[self openSession];
} else {
// No, display the login page.
[self showLoginView];
}
return YES;
}
- (void)showLoginView
{
UIViewController *topViewController = [self.navController topViewController];
UIViewController *modalViewController = [topViewController modalViewController];
// If the login screen is not already displayed, display it. If the login screen is
// displayed, then getting back here means the login in progress did not successfully
// complete. In that case, notify the login view so it can update its UI appropriately.
if (![modalViewController isKindOfClass:[SSLoginViewController class]]) {
SSLoginViewController* loginViewController = [[SSLoginViewController alloc]
initWithNibName:#"SSLoginViewController"
bundle:nil];
[topViewController presentViewController:loginViewController animated:NO completion:nil];
} else {
SSLoginViewController* loginViewController =
(SSLoginViewController*)modalViewController;
[loginViewController loginFailed];
}
}

MPMediaPickerController - iOS7

I developed test application on iOS 7 that pick the music from music library using MPMediaPickerController.
But when I present the media picker controller,it shows empty screen.
This is the code
(void) pickSong
{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = NSLocalizedString(#"Select Your Favourite Song!", nil);
[mediaPicker loadView];
[self.navigationController presentViewController:mediaPicker animated:YES completion:nil];
}
#pragma mark - MPMediaPickerController delegate
(void) mediaPicker:(MPMediaPickerController *) mediaPicker2 didPickMediaItems:(MPMediaItemCollection *) mediaItemCollection {
[self dismissViewControllerAnimated:YES completion:nil];
MPMediaItem *mediaItem = [[mediaItemCollection items] objectAtIndex:0];
self.item.soundName = [mediaItem valueForProperty:MPMediaItemPropertyTitle];
self.item.soundUrl = [[mediaItem valueForProperty:MPMediaItemPropertyAssetURL] absoluteString];
}
(void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
Please help me out.
This is an iOS bug, but it only occurs when running a 32 bit build on a 64 bit (A7) device (Only iPhone 5S for now). To work around it, add a 64 bit architecture to your app. (Open build settings in xcode, and change Architecture from $ARCHS_STANDARD to $ARCHS_STANDARD_INCLUDING_64_BIT.) You will then probably need to fix a number of compile, link and runtime issues. See Apple's 64-Bit Transition Guide.
Seems like there is a bug in ios7 where it doesn't like to be presented inside a uinavigation controller - try presenting it directly from a view controller.
I had the same problem and for me the solution was a combination of two of the solutions presented here. First I had to convert my app to be 64-bit ready by changing Architectures to "standard... (including 64-bit)". Once I corrected all the warnings that caused, I had to change the MPMediaPickerController to be presented modally rather than on the navigation stack:
- (IBAction)didSelectMusicPicker:(id)sender {
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"Add songs to play", "Prompt in media item picker");
//[self.navigationController pushViewController:picker animated:YES];
[self presentViewController:picker animated:TRUE completion:NULL];
}
Of course, I also needed to change mediaPicker:didPickMediaItems: and mediaPickerDidCancel: to use dismissViewControllerAnimated. Once all that was fixed, the picker worked as expected on both iPhone 4 and iPhone 5S running iOS 7.
a thought: is the presented screen completely empty, or are you getting the navigation bar at the bottom but with no tracks listed? I've noticed that as of iOS 7 the picker now defaults to opening to the Playlist tab (it used to open to Albums, if I recall)… if you have no playlists on the device that would account for the empty screen…
I can see the list of songs and select the songs. But I cannot dismiss the view controller on pressing "Done". I've tried PresentViewController since Modal controller is deprecated.
- (IBAction) showMediaPicker: (id) sender {
picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"AddSongsPrompt", #"Prompt to user to choose some songs to play");
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated:YES];
[self.picker removeFromParentViewController];
[self presentViewController:picker animated:YES completion:nil];
// [picker release];
}
// Responds to the user tapping Done after choosing music.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
[self.picker removeFromParentViewController];
[self dismissViewControllerAnimated:YES completion:nil];
//
[self.delegate updatePlayerQueueWithMediaCollection: mediaItemCollection];
// [self.mediaItemCollectionTable reloadData];
// [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}
I've tried RemovefromSuperview also, nothing seems to work. I'm testing this on an iPhone 6 simulator and an iPhone 5 with iOS 8.1.3.
Anyone???
I also have the same problem before. But I found out just need to restart the device after upgrade. The music picker appear again.

Game Center Calling Leaderboard function not responding?

I am calling the leader board like this:
-(void)viewscores:(SPEvent*)event
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil) {
leaderboardController.leaderboardDelegate = self;
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window addSubview: self.rootViewController];
[self presentModalViewController: leaderboardController animated: YES];
}
}
When I Click the leader board button, I receive an error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIViewController presentModalViewController:animated:]: unrecognized selector sent to class 0x3e2fc7f8'
Is this normal?
You should probably call the function in a viewController. In one of my app's the code looks like this:
-(IBAction)showLeaderBoard {
GKLeaderboardViewController *leaderBoardCont = [[GKLeaderboardViewController alloc] init];
if (leaderBoardCont) {
leaderBoardCont.category=#"1S";
leaderBoardCont.timeScope=GKLeaderboardTimeScopeWeek;
leaderBoardCont.leaderboardDelegate=self;
[self presentModalViewController:leaderBoardCont animated:YES];
}
}
and then you should also implement the delegate method:
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
[self dismissModalViewControllerAnimated:YES];
viewController = nil;
}
Here 1S is the identifier for the leader board you created in iTunes Connect. Hope this helps.
Edit: since you are still having problems, check these tutorials out. They cover everything about leader boards and achievements.
1st part
2nd part
You're sending the presentModalViewController message to an object that doesn't recognize it. So the class you wrote in your "Game.m" file doesn't inherit from UIViewController. Dunno what framework you're using, but you'll have to init a UIViewController instance to show the GameCenter view.

iAds Loading Throttled After Re-Launching App From Background (Also Happens In iAdSuite)

I am trying to implement the NavigationBanner iAdSuite example into my project so that a I can share a single AdBannerView instance across multiple view controllers, but I keep getting the following error:
Error Domain=ADErrorDomain Code=2 "The operation couldn’t be completed. Loading throttled
I have copied the relevant code exactly from the current iAdSuite into my own app and am getting this error. In fact, this error is repeatable in Apple's own iAdSuite example for NavigationBanner (which is the example I am trying to implement). The error can be seen by adding:
NSLog (#"%#",error);
to:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
To replicate the problem in iAdSuite do the following:
Turn your device Airplane mode to On
Launch iAdSuite NavigationBanner from Xcode. This generates an error right away "ADErrorDomain error 1".
Exit the app by pressing the Home button on your device, then turn Airplane mode Off.
Re-launch NavigationBanner by tapping the icon, and the error appears.
This is a problem for my application because I want to hide the iAd if there is no connectivity, and then have it re-appear once connectivity resumes. If the app receives the throttling error, then there will be a long delay before it can receive another ad.
How can the throttling error be avoided? I was thinking that the bannerView needs to be removed and then re-added, but could not figure out how to do this correctly.
One last thing to note is that the current iAdSuite uses ARC while my application does not. Even so, the error occurs with both my app and iAdSuite.
Try detecting the network status with the "Reachability" project code by Apple. There is an ARC compatible version on Github. (https://github.com/tonymillion/Reachability) Once you have Reachability.h imported in your header file, you can try the code below. Reachability will detect if any sort of connection is available and if not, then the iAd will be moved off screen. Hope this helps!
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable)
{
// No internet connection. We need to move the iAd off screen.
NSLog(#"No network connection. iAd will hide.");
banner.frame = CGRectOffset(banner.frame, 320, 0);
}
if(status == ReachableViaWifi)
{
banner.frame = CGRectOffset(banner.frame, your position here);
}
if(status == ReachableViaWWAN)
{
banner.frame = CGRectOffset(banner.frame, your position here);
}
}
/*Implement the iAd in app delegate and use the applicationDidBecomeActive method.Here I use #import "Reachability.h" class downloaded from Github Here is the code.*/
// AppDelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate,ADBannerViewDelegate>
{
BOOL iAdLauchFlag;
ADBannerView *bannerView;
UILabel *notifier ;
UIView *iAdview;
}
// AppDelegate.m
#import "AppDelegate.h"
#import "Reachability.h"
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
LauchFlag=NO;
notifier=[[UILabel alloc]init];
notifier=[[UILabel alloc]initWithFrame:CGRectMake(0.0f, 40.0f, bounds.size.height, 30)];
iAdview =[[UIView alloc]initWithFrame:CGRectMake(0.0f,bounds.size.width,bounds.size.height, 30)];
}
-(void) applicationDidBecomeActive: (UIApplication *) application
{
NSLog(#"applicationDidBecomeActive");
if ( [self connectedToNetwork] )
{
if(!LauchFlag)
{
CGRect bounds=[[UIScreen mainScreen] bounds];
NSLog(#"allocated banner view");
bannerView = [[ADBannerView alloc]
initWithFrame:CGRectMake(0.0f, 30.0f, bounds.size.height, 30)];
[notifier setText:#" Connecting to iAd service......."];
[iAdview addSubview:notifier];
}
bannerView.delegate = self;
}
else
{
if(LauchFlag)
{
[bannerView removeFromSuperview];
[bannerView release];
LauchFlag=NO;
}
[notifier setText:#" iAd failed to launch due to internet connection problem "];
[iAdview addSubview:notifier];
}
}
-(BOOL)bannerViewActionShouldBegin:
(ADBannerView *)banner
willLeaveApplication:(BOOL)willLeave{
return YES;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"bannerView:(ADBannerView *)banner didFailToReceiveAdWithError");
if ([self connectedToNetwork]) {
[notifier setText:#" Launching iAd ............"];
NSLog(#"Reachable");
}
else {
[notifier setText:#"error: iAd failed to launch due internet connection problem "];
NSLog(#"Not Reachable");
}
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"bannerViewDidLoadAd");
[notifier removeFromSuperview];
[iAdview addSubview:bannerView];
LauchFlag=YES;
}
- (BOOL) connectedToNetwork
{
Reachability *r = [Reachability reachabilityWithHostName:#"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
BOOL internet;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
internet = NO;
} else {
internet = YES;
}
return internet;
}
// viewcontroller1
#import "AppDelegate.h"
- (void)viewDidLoad
{
AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
[[self view] addSubview:appdelegate.iAdview];
}
//viewcontroller2
#import "AppDelegate.h"
- (void)viewDidLoad
{
AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
[[self view] addSubview:appdelegate.iAdview];
}