After a lot of searching on here I finally found a way for Game Center to display in SpriteKit but now I can't get the leaderboardViewControllerDidFinish method to call. I use this code in a different app and it works fine but for some reason with the code being modified for SpriteKit its just not working. Thank you in advance!
Here is a sample of my code:
- (void)showGameCenterButtonPressed:(id)sender {
{
if ([GKLocalPlayer localPlayer].authenticated == NO) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"You must enable Game Center!"
message:#"Sign in through the Game Center app to enable all features"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
} else {
GKGameCenterViewController *leaderboardViewController = [[GKGameCenterViewController alloc] init];
if (leaderboardViewController != NULL)
{
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: leaderboardViewController animated: YES completion:nil];
}
}
}
}
- (void)leaderboardViewControllerDidFinish:(GKGameCenterViewController *)viewController {
NSLog(#"in leaderboardControllerDidFinish");
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
To answer my own question...
I just took the code straight from Apple
- (void)showGameCenterButtonPressed:(id)sender {
{
if ([GKLocalPlayer localPlayer].authenticated == NO) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"You must enable Game Center!"
message:#"Sign in through the Game Center app to enable all features"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
} else {
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: gameCenterController animated: YES completion:nil];
}
}
}
}
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController*)gameCenterViewController {
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
Related
I have implemented the following and camera is opened but app is crashed and sometime when open and take the pictures then app is crasshed and log only show "Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates Received memory warning."
The same functionality I have used for take the image from gallery and its working.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
if (buttonIndex==0) {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Device has no Camera!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}else{
[self performSelector:#selector(loadCamera) withObject:nil afterDelay:1.0];
}
}
}
-(void)loadCamera{
picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion:NULL];
}
Can anyone help.
Solved it by following code:
-(void)loadCamera{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
dispatch_async(dispatch_get_main_queue(), ^{
picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion: nil];
});
}
}
This code worked for me with iOS 9.2 and xCode 7.2
- (IBAction)takeAPhoto:(VSButton *)sender {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}else {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
}
[self performSelector:#selector(loadCamera) withObject:nil afterDelay:1.0];
-(void)loadCamera
{
if ([UIIagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera)
{
picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion:NULL];
}
}
I can load up leaderboards with no problem. But I can't get it to close when the "Done" button is clicked.
How I'm opening it:
- (IBAction)leaderboardsClicked:(id)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Error"
message: #"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alert show];
}
}
How I'm closing it:
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
NSLog(#"test");
[self dismissViewControllerAnimated:YES completion:nil];
}
EDIT:
The method isn't running at all; so "test" doesn't even get printed.
And I added <GKGameCenterControllerDelegate> to my ViewController's protocol.
Try this instead:
- (IBAction)leaderboardsClicked:(id)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
leaderboardController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Error"
message: #"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alert show];
}
}
And:
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
I have a problem and can't know the reason or solution
I have AddDelegate and another ViewController, in this ViewController I add FBFriendPickerViewController, and ViewController will be added to AppDelegate ..
I add ViewController to AppDelegate like this: ( this ViewController is SocialSharing class )
if( socialSharing == nil )
socialSharing = [[SocialSharing alloc] init];
[_window.rootViewController.view addSubview:socialSharing.view];
And add FBFriendPickerViewController in ViewController(SocialSharing) like this:
-(void)shareOnFaceBook:(NSNotification *) notification
{
if( shareOnUserOrFriendWallBtnIndex == 0 )
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSURL *candidateURL = [NSURL URLWithString:contentDataToShare];
if (candidateURL && candidateURL.scheme && candidateURL.host) {
[facebookSheet setInitialText:#"See this link .."];
[facebookSheet addURL:candidateURL];
}
else // Event ***
{
[facebookSheet setInitialText:[NSString stringWithFormat:#"%#%#%#",[[appDelegate.extrasOverlayView.markerData.btnsArr objectAtIndex:0] objectForKey:#"markerName"],#" .. \n", contentDataToShare]];
[facebookSheet addURL:[NSURL URLWithString:lastVideoLink]];
}
//Brings up the little share card with the test we have pre defind.
[appDelegate.window.rootViewController presentViewController:facebookSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now, make sure you have at least one Facebook account setup and your device is using iOS." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
else if( shareOnUserOrFriendWallBtnIndex == 1 )// post on friend's wall
{
if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]] )
{
NSLog(#"Facebook is inastalled on this device.");
if( friendPickerController == nil )
{
friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.delegate = self;
if( !( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) )
friendPickerController.title = #"Select Friends";
}
[friendPickerController loadData];
// Present view controller modally
[self presentViewController:friendPickerController animated:YES completion:nil];
}
else{
NSLog(#"This device has no Facebook app.");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't invite friends, Facebook app isn't installed, please install it and retry again." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
}
and dismiss friendPickerController from SocialSharing like:
- (void)facebookViewControllerCancelWasPressed:(id)sender
{
NSLog(#"Friend selection cancelled.");
[self dismissViewControllerAnimated:YES completion:nil];
}
I used:
[friendPickerController dismissModalViewControllerAnimated:YES];
OR //[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:Nil];
OR //[self dismissModalViewControllerAnimated:YES];
It works good for only first time, once, friendPickerController appears and dismiss when close, BUT when call to open again, I have this error:
"Thread 1: signal SIGBRT"
FOR the line of :
[self presentViewController:friendPickerController animated:YES completion:nil];
Note: when I add friendPickerController on AppDelegate directly (in class of AppDelegate) without another class (here is SocialSharing ViewController), it works great ..
I'm working on IOS 7, and Facebook SDK 3.13..
So, What is the problem, How can I solve it ?
Thank you
What I did to solve my problem, I create friendPickerController in NORMAL CLASS , NOT ViewController, and add it on AppDelegate
[appDelegate.window.rootViewController presentViewController:friendPickerController animated:YES completion:nil];
and dismiss by:
[appDelegate.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
And call this Class like:
if( socialSharing == nil )
{
socialSharing = [[SocialSharingClass alloc] init];
[socialSharing initSocialSharing];
}
Still, I don't know the problem, but that solved it. May that help anyone.
My application only supports landscape, and I'm having an issue only on the iPhone in iOS6 where the Game Center Leaderboard is the wrong orientation and partially off the screen. See attached:
I'm calling a modal UITableView from my view controller using an FPPopover like this:
HighScoresController *controller = [[HighScoresController alloc] init];
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
popover.arrowDirection = FPPopoverNoArrow;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
popover.contentSize = CGSizeMake(350,450);
else
popover.contentSize = CGSizeMake(350,350);
popover.delegate = self;
popover.title = #"High Scores";
[popover presentPopoverFromPoint: CGPointMake(mainView.center.x, self.view.center.y + 50)];
Then when one of the rows are clicked on this table, it calls the appropriate leaderboard in Game Center:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// authenticate into game center
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
if (error ==nil) {
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.category = [leaderboardIDs objectAtIndex:[indexPath row]];
[self presentViewController: leaderboardController animated: YES completion:nil];
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Game Center"
message:#"You need to sign into Game Center in order to view high scores" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert show];
}
}];
}
Any ideas on how to fix this issue? It's fine on iOS 5 with iPhone, as well as iPad for both iOS 5 and 6.
Thanks!
I am doing PayPal integration in my project. Everything is working, but at the end, the payment success method is not generated. My code for payment success is:
else if ([response isKindOfClass:[DoExpressCheckoutPaymentResponseDetails class]]) {
DoExpressCheckoutPaymentResponseDetails *dres = (DoExpressCheckoutPaymentResponseDetails *)response;
if (dres.PaymentInfo.count > 0 && ((PaymentInfo *)[dres.PaymentInfo objectAtIndex:0]).TransactionID.length > 0)
{
[self paymentSuccess:((PaymentInfo *)[dres.PaymentInfo objectAtIndex:0]).TransactionID];
}
else
{
NSLog(#"Error came");
[self paymentFailed];
}
}
and the payment success method is...
UINavigationController *navController = self.navigationController;
orderResultsViewController.forDelivery = ((ReviewOrderViewController *)[navController.viewControllers objectAtIndex:navController.viewControllers.count - 2]).forDelivery;
orderResultsViewController.transactionID = transactionID;
[navController popViewControllerAnimated:FALSE];
[navController setNavigationBarHidden:FALSE animated:TRUE];
[navController pushViewController:orderResultsViewController animated:TRUE];
If you got it then point me in some direction to go...
-(void)paymentFailed {
[self.navigationController popViewControllerAnimated:TRUE];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Order failed"
message:#"Your order failed. Touch \"Pay with PayPal\" to try again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
I am getting above alert view and payment order failed....