Game Center leaderboards shows No data available - ios

I want the App to show all leaderboard when a user logs into the Game Center. I wrote the following code to do that, and it works OK until I once disconnected the network.
The App started without network, but local Game Center was logged in. When I reconnected the network and tapped to show leaderboards, it showed "No data available". I must terminate and reopen the App to make it work.
Oddly enough, if I added setLeaderboardIdentifier and did the same thing above, the specified leaderboard could be shown after network connected again.
Anything Wrong? Thanks
- (void)showGameCenter{
GKGameCenterViewController *gameView = [[GKGameCenterViewController alloc] init];
if(gameView != nil){
gameView.gameCenterDelegate = self;
[gameView setViewState:GKGameCenterViewControllerStateLeaderboards];
[gameView setLeaderboardTimeScope:GKLeaderboardTimeScopeAllTime];
// //[gameView setLeaderboardIdentifier:#"xxxxxxxxx"];
[self presentViewController: gameView animated: YES completion:nil];
}
}

Related

cocos2d-js game iOS Crash when enter the game at the second time

We are using cocos2d-js to develop an iOS App which can launch different games. So I add an button in the native app viewcontroller and start the game by clicking the button, just like this:
-(void)didClickGame2Btn:(id)sender
{
//加载游戏
cocos2d::Application *app = cocos2d::Application::getInstance();
// Initialize the GLView attributes
app->initGLContextAttrs();
cocos2d::GLViewImpl::convertAttrs();
// Use RootViewController to manage CCEAGLView
RootViewController *rootViewController = [[RootViewController alloc] init];
rootViewController.wantsFullScreenLayout = YES;
[self.navigationController presentViewController:rootViewController animated:YES completion:^{
// IMPORTANT: Setting the GLView should be done after creating the RootViewController
cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView((__bridge void *)rootViewController.view);
cocos2d::Director::getInstance()->setOpenGLView(glview);
NSString *documentDir = [SEGetDirectories dirDoc];
NSString *wPath = [NSString stringWithFormat:#"%#/GameData/Game2",documentDir];
NSLog(#"document------:%#",documentDir);
std::vector<std::string> searchPathList;
searchPathList.push_back([wPath UTF8String]);
cocos2d::FileUtils::getInstance()->setSearchPaths(searchPathList);
//run the cocos2d-x game scene
app->run();
}];
[[UIApplication sharedApplication] setStatusBarHidden:true];
}
the rootViewController contains the game view. And then we add an button in the game, which is used to exit the game. The click event code of the exit game button likes:
//exit the game and close the view controller
gameEndCallBack:function(sender){
cc.log("director end............");
cc.director.end();
var ojb = jsb.reflection.callStaticMethod("ViewControllerUtils", "dismissCurrentVC");
}
We use the reflection to dismiss the rootViewController:
+(void)dismissCurrentVC
{
UIViewController *currentVC = [ViewControllerUtils getCurrentVC]; //这里获取最顶层的viewcontroller
[currentVC dismissViewControllerAnimated:YES completion:^{
NSLog(#"xxx");
}];
}
Everything is ok when the first time to enter the game, but after dismissing the rootViewController, we try to enter the game again, it crash.
The crash line is in the ScriptingCore::runScript metod and executing the code:
evaluatedOK = JS_ExecuteScript(cx, global, *script, &rval);
And the crash info is "exc_bad_access".
It is much the same problem as this topic, but the approaches in it did not solve the problem.
http://discuss.cocos2d-x.org/t/how-to-destroy-a-cocos-game-on-ios-completely/23805
This problem has been confusing me serveral days, I have no solution for this. Can anyone give me some help?
You can make the app to support multiple games with in the app.
All you have done is required but in addition to that please follow the below instructions.
First of all, cocos provide a singleton instance of cocos2d::Application that can not be restarted again especially in iOS. So the approach of ending the Director cc.director.end(); won't help you.
You should start the application only once by using the function call cocos2d::Application::getInstance()->run(); and next time if you want to start the game layer, you should not call this method again.
Instead, just pause cocos2d::Director::getInstance()->pause(); and resume cocos2d::Director::getInstance()->resume(); the director when you want to stop the game.
In this approach, if you dismiss/dealloc the view-controller instance then you should create the glview cocos2d::GLView instance again without calling the run method.
One more problem is, take care of the delay in loading the new scene. GLView will display the previous game scene for a while. Do a work around that will show blank screen while the new scene is ready.
Hope this will help you.

Camera has black screen in UIImagepickercontroller in iOS

I'm facing the black screen preview in UIIMagePickercontroller. I tried many solutions but cannot solved that. Any body can help me to solve that? It's always happens when I open the photo library and select some photos, then add new cellItem in UICollectionview, after that I open camera to take new photo and the issue is happened.
Here is my code used to open Camera:
-(void)actionLaunchAppCamera
{
dispatch_async(dispatch_get_main_queue(), ^{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (self.cameraPickerController == nil) {
self.cameraPickerController= [[UIImagePickerController alloc] init];
self.cameraPickerController.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraPickerController.showsCameraControls = YES;
self.cameraPickerController.allowsEditing = YES;
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// self.cameraPickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto||UIImagePickerControllerCameraCaptureModeVideo;
self.cameraPickerController.delegate = self;
self.cameraPickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.cameraPickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.cameraPickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.cameraPickerController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:self.cameraPickerController
animated:YES completion:^
{
// BE SURE TO USE a completion block!!!
// completion stuff in here
}];
}
}
});
}
Thanks in advance.
I tried everything without luck until I set my Bundle Display Name to "whatever", in the Info.plist.
After this, the app asked for permissions as expected and the camera works.
I only wasted a day on this, which seems well below the median on StackOverflow. Hope it rescues others from this torturous bug.
The problem is not your code. It's apple's API. You can make see the same problem in Apple contact, if you edit the picture, save it and then go back and edit it agin. Then you will have a black preview. Take a picture any way and repeat the process, then it will be fine. It also does it in text message picture. Reset the device to factory settings and everything will work for a while. I have reported to Apple 3 months ago and still nothing from them. One would think if Apple had a bug report in their core apps they would fix it. This problem has really been a pain and yet IOS 6 had no problems.

Access all UIAlertView object as a global object to control it Universally(to resolve CRASH in alert after deallocating the view contoller)

My requirement is to make my app's third tab as the home screen,and also whenever the user moves the app in background and while again moving the app to foreground it should be the home screen as our third tab instead the app is in any of the places in the app.
This issue is handled(making third tab as home screen instead the app is in any of the places/scenarios in the app).,But i have an issue now which is generated by this resolution.
Problem :- If any alert is displaying in any view and we are making the app background-foreground ,the app comes to the third tab from that screen,and the alert is still there and if we click on the alert button ,then as per the rules of IOS the "self" object of the screen of alert is deallocated(because now we are in the home screen and the alert is here) and app CRASHES !
Tried some resolutions :-
1.In a screen ,I made an global object of UIAlertView and using below line of code in applicationDidBecomeActive method of the Screen...
[_alertToRemoveContact dismissWithClickedButtonIndex:1 animated:NO];
This is working code for this view,but my problem with resolution is that i need to create a global object of alert view in all places of the app which is a very much time consuming task because i am using around 250 alerts in the project.
2.I am killing the app whenever it moves to background ,In this resolution the problem is that my app will not work its downloading functionality in background cause the app is killed.
Need help for the resolution of this issue if any one need more explanations,please leave comments.
My Crash Log....
* -[ContactShowViewController respondsToSelector:]: message sent to deallocated instance 0x1138c4e0*
*Where ContactShowViewController will differ a/c to the screen
Thanks in advance !!!
Let's try singleton:
__strong static AlertUtil* _sharedInstance = nil;
#implementation AlertUtil
{
UIAlertView *alertView;
}
+ (AlertUtil *)sharedInstance
{
#synchronized(self)
{
if (nil == _sharedInstance)
{
_sharedInstance = [[AlertUtil alloc] init];
}
}
return _sharedInstance;
}
- (void)showConfirmAlertWithMessage:(NSString *)msg cancelBtnTitle:(NSString *)btn1 okbtnTitle:(NSString *)btn2 delegate:(id)delegate tag:(int)tag
{
alertView = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:delegate cancelButtonTitle:btn1 otherButtonTitles:btn2, nil];
alertView.tag = tag;
[alertView show];
}
- (void)cancel
{
if (alertView){
[alertView dismissWithClickedButtonIndex:0 animated:NO];
}
}
I have resolved this issue with the help of below solution :-
1.I created an app delegate instance of UIAlertView.
2.I implemented an alert view delegate method "will present alert view...",this method gives me all the alert view objects as a parameter where i have assigned it to my app delegate object of alert view.
3.On application life cycle method "applicationDidEnterBackground" i am using below code ...,which resigns my alert dailog on coming from background to foreground...
if ([AppDelegate shared].alertObserver)
{
//Dismissing alert which was shown before moving to background
[[AppDelegate shared].alertObserver dismissWithClickedButtonIndex:0 animated:NO];
[AppDelegate shared].alertObserver=nil;
}

Send GameCenter friendrequest

At the moment I'm working on a iPhone app and I have a problem.
I want, that the player can send a gamecenter friendrequest.
In the apple Guide there are two methods I'm interested in.
The first would be
- (void)addRecipientsWithPlayerIDs:(NSArray *)playerids
and the second would be
- (void)setMessage:(NSString *)message
Now I don't know to put them in the right order to get on.
How can I set the player ID's and the message, and after that, how can I send the request.
Suppose you have player ids in friendsArray. Then try this:
GKFriendRequestComposeViewController *friendRequestViewController = [[GKFriendRequestComposeViewController alloc] init];
friendRequestViewController.composeViewDelegate = self;
[friendRequestViewController setMessage:#"Add your message here"];
if (friendsArray)
{
[friendRequestViewController addRecipientsWithPlayerIDs: friendsArray];
}
[self presentModalViewController: friendRequestViewController animated: YES];
Hope this helps.. :)

Game Center ViewController not appearing when testing on phone

I'm using iOS6 and my phone is a 4S.
I'm using code from the GKLeaderboards example to get Game Center working and the local player authenticated. This code I've imported into my own Sparrow framework scaffold project.
This seems to work totally fine on the simulator, I get the "welcome back xxxx, ** sandbox mode *" msg.
But when I test it on the actual iPhone, my game (which right now just consists of lots of tiles on the screen) slows down to a crawl, and no Game Center msg appears.
Looking at code, because I'm logged in with a different Game Center account on the phone (i'e not the sandbox one) then I think it's trying to present the log in with new account view, but it's not appearing.
The code I'm using is...
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
// If there is an error, do not assume local player is not authenticated.
if (viewController != nil)
{
[mainViewController presentViewController:viewController animated:NO completion:nil];
//store this view controller pointer
NSLog(#"viewController != nil");
}
else if (localPlayer.isAuthenticated)
{
NSLog(#"Authentication changed: player authenticated.");
}
else
{
NSLog(#"can't log in");
}
}
I think the problem is being caused by this line...
[mainViewController presentViewController:viewController animated:NO completion:nil];
The game doesn't seem to crash but there seems to be something going wrong causing it all to slow right now, any ideas as to what could cause this?
Ok I seem to have gotten this working. Basically I didn't have mainViewController set properly.

Resources