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];
}
Related
I'm having what seems to be a fairly common problem, but my searches and implementations of solutions have not worked out.
I've built a Cocos2d game that is intended to be landscape only, but needs to access Gamecenter. Gamecenter is working, with portrait mode enabled, but it's also allowing the game to flip to portrait mode too.
I've attempted the following fixes:
Game center login lock in landscape only in i OS 6
GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation
Error in iOS 6 after adding GameCenter to a landscape-only cocos2d app
Cocos 2d 2.0 shouldAutorotate not working?
I believe the problem is that I've built the game using CCLayers instead of UIViewControllers
Example:
MenuLayer.h
#interface MenuLayer : CCLayer <GKAchievementViewControllerDelegate, GKLeaderboardViewControllerDelegate, UINavigationControllerDelegate>{
..my header info..
}
MenuLayer.m
...
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate {
return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}
-(void)authenticateLocalPlayer
{
GKLocalPlayer * localPlayer= [GKLocalPlayer localPlayer];
if(localPlayer.authenticated == NO)
{
NSString *reqSysVer = #"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[[GKLocalPlayer localPlayer] setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (viewcontroller != nil) {
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] presentModalViewController:viewcontroller animated:YES];
}else if ([GKLocalPlayer localPlayer].authenticated)
{
//do some stuff
}
})];
}
else
{
[localPlayer authenticateWithCompletionHandler:^(NSError *error){
if(localPlayer.isAuthenticated)
{
//Peform Additionl Tasks for the authenticated player.
}
}];
}
}
}
...
Since I've built the game using CCLayers instead of UIViewControllers, what alternatives do I have? Am I correct in assuming that CCLayers don't call use supportedInterfaceOrientations or shouldAutorotate?
Or am I supposed be changing this code somehow to fix the problem:
// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
This frustrated me for awhile too. After digging around for awhile on the 'Net I found a couple of sources and some worked with iOS 6, some with iOS5, but I had to make some modifications so that it worked the way I wanted on both iOS5 and iOS6. This is the code I am using, it works on my iPhone using 5.1 and 6. Note that the Game Center login still comes up in portrait orientation, there doesn't appear to be anything you can do about that. But the rest of the game will remain in landscape mode.
enable portrait mode as a supported orientation in your build settings (info.plist).
Create a new subclass of UINavigationController. Name this class whatever makes sense to you.
In your AppDelegate, include your new custom UINavigationController header file.
In your App Delegate, comment out the original call and instead call your custom class.
That should do the trick. Here is the code from my custom class:
#import <UIKit/UIKit.h>
#interface CustomNavigationViewController : UINavigationController
-(UIInterfaceOrientation) getCurrentOrientation;
#end
And the implementation file:
#import "CustomNavigationViewController.h"
#interface CustomNavigationViewController ()
#end
#implementation CustomNavigationViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// This is required to allow GameCenter to login in portrait mode, but only allow landscape mode for the rest of the game play/
// Arrrgg!
-(BOOL) shouldAutorotate {
return YES;
}
-(NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight; // or left if you prefer
}
-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskLandscape;
else {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}
-(UIInterfaceOrientation) getCurrentOrientation {
return [[UIDevice currentDevice] orientation];
}
#end
Note that last method getCurrentOrientation isn't required I just put that in there in case I wanted to determine what the current orientation is.
The custom class is called in AppDelegate.m like this: (comment out the original code)
navController = [[CustomNavigationViewController alloc] initWithRootViewController:director];
window.rootViewController = navController;
navController.navigationBarHidden = YES;
[window makeKeyAndVisible];
Hope this helps.
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.
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.
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
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