How to run iphone GameCenter app from my app? - iphone

I think the best way and may be only way is using the URL schemes with [[UIApplication sharedApplication] openURL:...]. But I can't find URL scheme for game center..

You can launch the Game Center app by using the gamecenter: URL scheme:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:"]];

In iOS 6.0 there's a new way quite cool to show Game Center using GKGameCenterViewController.
For using it your view controller must acts as a delegate to the GKGameCenterViewController:
#interface ViewController : UIViewController <GKGameCenterControllerDelegate>
And then for displaying the Game Center view:
- (void)showGameCenter
{
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
[self presentViewController: gameCenterController animated: YES completion:nil];
}
}
//Called when the player is done interacting with the GKGameCenterViewController
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
If the user it's under iOS 5.0, you can only use the URL schemes like you said before.

Try the Apple example code. It explain how your app work with gamecenter. http://developer.apple.com/library/ios/#samplecode/GKTapper/Introduction/Intro.html

Related

iOS: Launch AppStore page within my App

I seen games like
Kingdom Clash
Castle Story
being able to launch AppStore within their game without minimizing their game.
The AppStore page will just slide in from bottom, show a game page, and players can download that game, key in their password, close the page and they are still in the game.
Is there a way to do this?
I can only minimize my own app, and open the Appstore.
Please advise.
Thanks
You can use SKStoreProductViewController class
Import StoreKit framework
#import <StoreKit/StoreKit.h>
Implement the SKStoreProductViewControllerDelegate
#interface MyViewControllerClass : NSObject <SKStoreProductViewControllerDelegate> {
}
- (void) openAppStore
{
if( NSStringFromClass([SKStoreProductViewController class]) != nil )
{
SKStoreProductViewController *viewCont = [[SKStoreProductViewController alloc] init];
viewCont.delegate = self;
[viewCont loadProductWithParameters:[NSDictionary dictionaryWithObject:#"APP_ID_FROM_ITUNES" forKey:SKStoreProductParameterITunesItemIdentifier] completionBlock:nil];
[self.navigationController presentViewController:viewCont animated:YES completion:nil];
}
else
{
// open safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.apple.com/us/app/facebook/id284882215?mt=8"]];
}
}
// SKStoreProductViewControllerDelegate
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)productViewController
{
[productViewController dismissViewControllerAnimated:YES completion:nil];
}

share photo from Camera Roll via my app

i want to develop a app that can share image to social network, it work well but i want my app have some advance function
i see that in ios6, it can share image from photo library by tap sharing button
now i want my app in the list app in share screen, how can i do that ?
- (void) loadMoreData
{
[self requestServerGetTimeline];
}
- (void) btnImageClicked:(NSString *)photoId
{
DetailImageController *detailImageController = [[DetailImageController alloc] initwithPhotoId:photoId withNavigationController:self.navigationController];
[self.navigationController pushViewController:detailImageController animated:YES];
[detailImageController release];
}
- (void) btnUsernameClicked:(NSString *)userId
{
MeshUserInformationController *detailUserController = [[MeshUserInformationController alloc] initWithNavigation:self.navigationController withUserId:userId];
[self.navigationController pushViewController:detailUserController animated:YES];
[detailUserController release];
}
You can't configure UIActivityView controller of Photos app but you can configure and make your own activities for your apps.

SKStoreProductViewController and GKHostedAuthenticateViewController don't have iPhone landscape modes

I'm implementing the StoreKit in-app app purchase interface and though it appears that the SKStoreProductViewController handles landscape on iPad, it does not appear to do so for my app on iPhone (it's universal).
The interface to SKStoreProductViewController is so limited, I don't appear to be able to manipulate the VC in any way. Has anyone else run into this? Any work-arounds?
When I run the code that works on iPad, the SKStoreProductViewController comes in from the left side, about an inch, and hangs out there until dismissed. It seems functional, but it messes up the VC that popped it up upon dismissal.
Here's the code:
// Set up the store vc (creating it if not already done)
if (self.storeVC == nil) self.storeVC = [[SKStoreProductViewController alloc] init];
self.storeVC.delegate = self;
NSDictionary *params = [NSDictionary dictionaryWithObject:appID forKey:SKStoreProductParameterITunesItemIdentifier];
// Set up a HUD in case connecting to the store takes a while
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self.storeVC loadProductWithParameters:params
completionBlock:^(BOOL result, NSError *error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (result) {
[self presentViewController:self.storeVC animated:NO completion:^{
}];
}
}];
Even better, we're having the same problem on the GKHostedAuthenticateViewController which is the viewcontroller returned from the method:
GKLocalPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error) {};
To reiterate: both of these are in portrait mode on iPhones (but not iPads) and they force the UI to go into portrait mode. Upon returning, your app's UI is messed up.
I ran into a similar problem. My universal app is in landscape, but while the SKStoreProductViewController works fairly well in landscape on the iPad, it presents with visual glitches on the iPhone.
My solution was to force the iPhone to present the SKStoreProductViewController in portrait. It's a little sad that it doesn't have the same orientation as the rest of the app, but it's better than having half the screen cut off.
I accomplished this by using the custom subclass below:
#interface SKPortraitStoreProductViewController : SKStoreProductViewController
#end
#implementation SKPortraitStoreProductViewController
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
return UIInterfaceOrientationPortrait;
else
return [super preferredInterfaceOrientationForPresentation];
}
#end
Try changing the modalPresentationStyle property on your SKStoreProductViewController before presenting it.
I have had good luck by setting it to UIModalPresentationPageSheet which seems to cover the landscape iPad case pretty well.

Wikitude SDK remove from superview

I have implement Wikitude SDK and I manage to initialize using this code:
-(IBAction)launchAR:(id)sender{
wikitudeAR = [[WikitudeARViewController alloc] initWithDelegate:self applicationPackage:nil applicationKey:nil applicationName:nil developerName:nil];
}
- (void) verificationDidSucceed {
BuddyFinderAppDelegate *appDel = (BuddyFinderAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDel.window addSubview: [wikitudeAR start]];
[window makeKeyAndVisible];
}
How I will go back to my MainViewController View?
(I want to call it from object "custombutton")
I guess your WikitudeARViewController delegate is application delegate.
1) Implement your own View controller , from where you want to launch AR Browser (on button click , preferably).
2) Instantiate WikitudeARViewController from your ViewController(button event) and making ViewController as delegate.
3) make view returned from [wikitudeAR start] to the ViewController.view (and not window.view).
Hope this helps.
you can use CustomMenuButtonDelegateImpl1.m
#implementation CustomMenuButtonDelegateImpl1
- (void) customMenuButtonPressed:(WTPoi *)currentSelectedPoi {
//NSLog(#"addpoi");
[[WikitudeARViewController sharedInstance] hide];
[UIApplication sharedApplication].statusBarHidden = NO;
}
#end
and it woroks very well

UIImagePickerController in Landscape

I have been searching for an answer to this, but cannot come up with anything. Apparently, iPhone SDK 3.0 made it possible that UIImagePickerController can be displayed in landscape mode - but I am not finding any method that will allow this. I would think that if the application is in landscape by default it would automatically adjust the image controller, but that is not working for me.
Thanks for any help!
No need to subclass; simply override the modalPresentationStyle property.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.modalPresentationStyle = UIModalPresentationFormSheet;
[viewController presentViewController:picker animated:YES completion:NULL];
I haven't checked whether this is illegal, but it worked for me.
If you want the UIImagePickerController to start(and stay) in Landscape orientation code:
//Initialize picker
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//Refer to the method didRotate:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didRotate:)
name:#"UIDeviceOrientationDidChangeNotification" object:nil];
//Set the picker source as the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Bring in the picker view
[self presentModalViewController:picker animated:YES];
The method didRotate:
- (void) didRotate:(NSNotification *)notification
{
//Maintain the camera in Landscape orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
If you just need to get rid of the warning try
#interface UIDevice ()
-(void)setOrientation:(UIDeviceOrientation)orientation;
#end
I've developed a UIImagePicker class in landscape mode. Works great for applications I've developed: hope it works for you too:
GitHub: https://github.com/imaginaryunit/iOSLandscapeThreadedImagePicker.git
I have an all-landscape app using UIImagePickerController too. Please be noted that if you call UIImagePickerController in Landscape mode, your app is possible to be rejected by Apple Review Team.
I devised a simple work around this issue which make use the shouldAutoRotate delegate. Apple approves this method for an all-landscape app.
See here for the details and downloadable full project source code.
Make a category of UINavigationController and add this method
- (BOOL)shouldAutorotate
{
return NO;
}
Subclass UIImagePickerController and override modalPresentationStyle as follows:
- (UIModalPresentationStyle)modalPresentationStyle
{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
return UIModalPresentationFormSheet;
}
return [super modalPresentationStyle];
}
The image-picker is a form-sheet now and no longer in fullscreen-mode, but it looks good in landscape-mode.
This should be totally app-store-safe.
This works for the gallery, not for taking pictures.
I solved this problem as follows: after each change in orientation, I simple re-create picker. Try this. Differently is too crooked...
I am developing a class that tries its best to work in landscape mode.
Check it out on GitHub: RACameraController