Open Game Center UI with Cocos2d-x - ios

I have set up so that my app can connect to the Game Center. I followed this guide and had a C++ class wrapper to call them in my other classes. I'm using iPad (iOS 5.1), iPod Touch 4th Gen (iOS 5.1), and iPhone 4s and 3GS to test. It works fine on iPad devices but for some unknown reason, it does not on iPhone and iPod. It properly connects to the Sandbox but the UI is not shown, or rather, the UI is somewhere off-screen.
What happens on the iPhone is:
If I'm not logged in and I access the Game Center, a login window appears. When I log in, nothing happens. However, the console says a view is added.
If I'm logged in and I access the Game Center, nothing happens. However, the console says a view is added.
If I access the Game Center before I get authenticated, the Game Center UI appears. However...
The Game Center is in Landscape Mode (no problem there, since my app is in landscape) but the top bar (the bar with the DONE button) is placed as if the orientation is portrait.
The whole UI is not shown, just ~30% of the screen.
This is how I launch the Game Center UI:
- (void)showLeaderboardForCategory:(NSString *)category
{
// Only execute if OS supports Game Center & player is logged in
if ( hasGameCenter )
{
// Create leaderboard view w/ default Game Center style
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
// If view controller was successfully created...
if (leaderboardController != nil)
{
// Leaderboard config
leaderboardController.leaderboardDelegate = self; // The leaderboard view controller will send messages to this object
leaderboardController.category = category; // Set category here
leaderboardController.timeScope = GKLeaderboardTimeScopeToday; // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime
// Create an additional UIViewController to attach the GKLeaderboardViewController to
myViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil ];
// Add the temporary UIViewController to the main OpenGL view
// NOTE: This is the part that I think is the suspect. I am not sure if iPhones and iPods support EAGLView.
[ [ EAGLView sharedEGLView ] addSubview:myViewController.view ];
// Tell UIViewController to present the leaderboard
[ myViewController presentModalViewController:leaderboardController animated:NO ];
NSLog( #"Leaderboard opened." );
}
}
}
Any help is appreciated and thanks in advance.
EDIT: Using OpenFeint is not an option.

Try this.Do not use 'EAGLView'
- (void) showLeaderboard
{
if (!gameCenterAvailable) return;
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil) {
leaderboardController.leaderboardDelegate = self;
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
currentModalViewController = [[UIViewController alloc] init];
[window addSubview:currentModalViewController.view];
[currentModalViewController presentModalViewController:leaderboardController animated:YES];
}
}

Related

Application rotates incorrectly as of iOS 8.3

I updated to iOS 8.3 and suddenly the Simulator I'm using to debug my XCode/GLES app (iPad 2) is having trouble responding to mouse clicks in the rightmost portion of the screen.
Our application's delegate class name points it to our AppDelegate which derives from UIViewController. Inside the AppDelegate's applicationDidFinishLaunching we then start creating windows - the top-level window being a UIWindow with its main child being a GLView. The application runs in landscape orientation.
Some (possibly important) pieces of code:
Info.plist:
Supported interface orientations
Item 0: Landscape (right home button)
int main(int argc, char *argv[]) // In main.m
{
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
}
#interface MyAppDelegate : UIViewController<UIApplicationDelegate>
{
...
}
#implementation MyAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[[UIApplication sharedApplication] setStatusBarHidden:YES]];
[[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGRect boundingRectangle = CGRectMake(0, 0, 768, 1024);
uIWindow = [[UiWindow alloc] initWithFrame:boundingRectangle];
uIWindow.rootViewController = self; // <-- Added this
[uIWindow setTransform:CGAffineTransformMakeRotation(DegreesToRadians(-90))]; // <-- Added this
boundingRectangle = CGRectMake(0, 260.0, 800, 480);
glViewWindow = [[GLView alloc] initWithFrame:boundingRectangle];
[uiWindow addSubView:glViewWindow];
[uiWindow makeKeyAndVisible];
}
#end
From other stack overflow discussions, it appears the problem is related to the warning we always get "Application windows are expected to have a root view controller at the end of application launch". So we added the line " uIWindow.rootViewController = self;".
This causes the application to be rotated 90 degrees. The simulator is correctly in landscape mode, but the application is in portrait. So we added the "setTransform" line seen above. That rotated the window into the right orientation, but (1) it's offset down and to the left, and (2) none of the mouse clicks work at all anymore (completely unresponsive).
Any ideas on what might be happening here? What can we try next?

don't know what I have to do to add Game Center leaderboard

I tried to add a Game Center leaderboard, first setting it on iTunes Connect but when I have to write the code in Xcode I don't know what I have to do. I want to open the leaderboard with a shake gesture and for that I will use this code in the ViewController.m file:
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(event.subtype == UIEventSubtypeMotionShake) {
// Code you want to run when the shake began
}
}
Is that code right?
And please can anyone help me what I have to do for appear the leaderboard when shaking?
Enable GameCenter in the Project's capabilities tab
Create a GKGameCenterViewController instance
Set the appropriate viewState property
If necessary, set the gameCenterDelegate property
Present the VC:
GKGameCenterViewController *vc = [GKGameCenterViewController new];
vc.viewState = GKGameCenterViewControllerStateLeaderboards;
vc.gameCenterDelegate = self;
[self presentViewController:vc animated:YES];

How to change home screen for Jailbreak Device programming

I'm a newbie in iOSOpenDev. I want to change the home screen on my jailbroken device. I use iOSOpenDev with Logos tweak to implement this
%hook SBUIController
- (void)finishLaunching
{
SBUIController *uicontroller = (SBUIController *)[%c(SBUIController) sharedInstance];
// Get _contentView & _iconsView from SBUIController
UIView* _contentView = [uicontroller valueForKey:#"_contentView"];
UIView* _iconsView = [uicontroller valueForKey:#"_iconsView"];
// Hidden _iconsView
_iconsView.hidden = YES;
// Add Sphere View
SphereViewManager *sphere = [[SphereViewManager alloc] initWithFrame:[UIScreen mainScreen].bounds];
sphere.frame = [UIScreen mainScreen].bounds;
sphere.tag = 20141201;
[_contentView addSubview:sphere];
}
After SpringBoard is restarted, my home screen is loaded. But when I tap an app to launch, and then I press the HOME button, my device returns to the old home screen. How do I prevent my HOME screen from returning the the old view?

iOS esri sdk - Multiple Popups using AGSPopupsContainerViewController

I am using AGSPopupsContainerViewController to display multiple popups when touching on mapView we fetch more than one AGSGraphics.
Here is my code:
NSMutableArray *popups =[[NSMutableArray alloc]init];
AGSPopupInfo *popupinfo;
for (AGSGraphic *g in Graphics ) {
popupinfo =[AGSPopupInfo popupInfoForGraphic:g] ;
AGSPopup* popup = [AGSPopup popupWithGraphic:g popupInfo:popupinfo];
popup.allowEditGeometry = false;
[popups addObject:popup];
}
if (!popupVC) {
self.popupVC = [[AGSPopupsContainerViewController alloc] initWithPopups:popups
usingNavigationControllerStack:false];
}else{
[self.popupVC showAdditionalPopups:popups];
}
self.popupVC.delegate = self;
self.popupVC.doneButton = self.customActionButton;
self.popupVC.style = AGSPopupsContainerStyleCustomColor;
self.popupVC.barItemTintColor = [UIColor redColor];
self.popupVC.pagingStyle = AGSPopupsContainerPagingStyleToolbar;
// Animate by flipping horizontally
self.popupVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// If iPad, use a modal presentation style
if([[AGSDevice currentDevice] isIPad])
self.popupVC.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:self.popupVC animated:YES completion:nil];
All works fine, I have the right number of pupups, the problem is that using the arrows in the toolbar I can only see the first and the last ones. Why? I am missing something?
Arrows are doing what they are supposed to do - using them will show you the first and the last popup. Swipe to the left (or right) and you'll see the rest of the popups.

On dismiss view iAds becomes black in ios 5 ipad.(dark black)

I have a tab based application. I have created an iAd object in app delegate class and using it in my three view controller class. It's working good on second tab's screen and third tab's screen. On second tab there is a table view, when clicking the row of that table view i navigate to the new view where i have used the same code for iAd. On clicking the iAd, iAd screen opens in landscape mode and when closing the screen becomes black and log the following.
[ADHostWindowController supportsOrientation:]: message sent to deallocated instance 0x100bc740
I created the object in app delegate like this:
self.bannerView = [[ADBannerView alloc]init];
[self.bannerView setDelegate:self];
I'm adding banner in view controllers like this:
[[[self appdelegate] bannerView] setFrame:CGRectMake(0, hightofView-180, 768, 66)]
All my view controllers are in portrait but iAds always open in landscape mode.
This is working in iOs 6, but not with iOS 5 on iPad. How do I fix this?
My guess your problem is not related to iAds but rather to memory issues.
It seems that an object of class kind ADHostWindowController is being deallocated prematurely.
My advice would be to make sure that ADHostWindowController is not released i.e (retainCount>=1) before supportsOrientation: is called to it. (which is definitely after the iAd opens).
For diagnosis: Try logging the retain count of that ADHostWindowController (then maybe retaining it one more time) before opening an iAd and see what happens.
Take a look at TabbleBanner code in iAd sample from Apple: https://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html
I don't investigate it in detail, but you need to follow the Apple iAd guide:https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/BannerAdvertisements/BannerAdvertisements.html
To create a ADBanner, in each UIViewController, add one to self.view
#property (strong,nonatomic) ADBannerView *bannerView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self createADBanner];
}
- (void)createADBanner{
self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.bannerView setDelegate:self];
[self.view addSubview:self.bannerView];
}
For beginning, you need to modify bannerView size and setCenter if need to place it at top or bottom.
- (void)viewDidLayoutSubviewsj{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
} else {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
}
}
And do the same when rotate:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
} else {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
}
}

Resources