Launching the app store dialog box? - iphone

I just noticed in iOS 6 that in your default Mail app, if you tap an itunes URL, an app store dialog box actually opens displaying the app's details.
There's no redirect to the app store! This box shows the screenshots, descriptions, etc. as if you were already in the app store.
I'm wondering if its possible to launch this box from inside my own app. I currently use itms-apps:// which naturally leaves my app, and goes to the app store.

If you are developing for iOS 6+ only, you can use SKStoreProductViewController.
Something like this:
SKStoreProductViewController *storeViewController =
[[SKStoreProductViewController alloc] init];
storeViewController.delegate = self;
NSDictionary *parameters =
#{SKStoreProductParameterITunesItemIdentifier:
[NSNumber numberWithInteger:333700869]}; //Identifier of the item you want to buy.
[storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
[self presentViewController:storeViewController
animated:YES
completion:nil];
}];
(Code from this tutorial.)

Related

how to come back to app when going to app store from app in ios

going to app store from app using this code
NSURL *myApplicationURL = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication]openURL:myApplicationURL];
Now how can i comeback from app store to app using cancel button.
Thanks for help.
Once you exit your Application you have no way to come back automatically, the user has to open the App again.
You can use show a modal SKStoreProductViewController (available on iOS 6) to show the AppStore inside your Application.
It is easy with the SKStoreProductViewController as redent84 answered and it is introduced in iOS 6+. With that users can buy your other apps right within the application.
First add StoreKit.framework to your project and add #import to header file.
Then find the Apple id of the app by going in iTunes connect manage applications and clicking on app will show you apple id and other details and pass that to the SKStoreProductViewController.
Below is the code
#import "ViewController.h"
#import <StoreKit/SKStoreProductViewController.h>
#interface ViewController ()<SKStoreProductViewControllerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMyApps];
}
-(void)AppStoreAction:(id)sender{
NSDictionary *appParameters = [NSDictionary dictionaryWithObject:#"533886215"
forKey:SKStoreProductParameterITunesItemIdentifier];
SKStoreProductViewController *productViewController = [[SKStoreProductViewController alloc] init];
[productViewController setDelegate:self];
[productViewController loadProductWithParameters:appParameters
completionBlock:^(BOOL result, NSError *error)
{
}];
[self presentViewController:productViewController
animated:YES
completion:nil];
}
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
In earlier versions you could link to the App Store: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.apple.com/de/artist/apple/id284417353?mt=12"]] but with this once you exit app you cannot go back to your app.
But with this SKProductViewController you can hit cancel button and go back to your app.
Hope it helps.
try this ........You can use a URL scheme if you have control of the web page. Simply add a link using your scheme.
If your scheme is myapp: then:
Return to the app
See this site for a tutorial. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/ refer:Return back to iPhone app from safari

Google + iPhone API sign in and share without leaving app

I recently integrated the Google + API in my App, it was a breeze, my only problem with it, is that everything requires you to leave the app and then come back (it uses URL schemes for this). This is not the behavior I would like, is there a way to directly call their services and do whatever I want with the responses just like in LinkedIn API?.
I really want to avoid going back and forth between safari and my app. Any suggestions/documentation is appreciated.
Thank you,
Oscar
UPDATE FROM GOOGLE
today, we released a new Google Sign In iOS SDK with full built-in
support for Sign In via WebView:
developers.google.com/identity/sign-in/ios The SDK supports dispatch
to any of a number of Google apps handling Sign In when present, with
WebView fallback after. In all cases, the Safari switch is avoided,
which we've seen to be the key element in avoiding app rejection.
We're looking forward to getting feedback from people using the new
SDK, and hope its use can replace the (ingenious and diligent)
workarounds people have implemented in the meantime.
THE METHOD BELLOW IS NO LONGER NEEDED
THIS METHOD HANDLES THE LOGIN INTERNAL WITH A CUSTOM UIWebView
THIS WORKS AND WAS APPROVED BY APPLE
My app got kicked from review cause of this
"The app opens a web page in mobile Safari for logging in to Google plus,
then returns the user to the app. The user should be able log in without opening
Safari first."
See this link https://code.google.com/p/google-plus-platform/issues/detail?id=900
I did solved it by following steps
1) create a subclass of UIApplication, which overrides openURL:
.h
#import <UIKit/UIKit.h>
#define ApplicationOpenGoogleAuthNotification #"ApplicationOpenGoogleAuthNotification"
#interface Application : UIApplication
#end
.m
#import "Application.h"
#implementation Application
- (BOOL)openURL:(NSURL*)url {
if ([[url absoluteString] hasPrefix:#"googlechrome-x-callback:"]) {
return NO;
} else if ([[url absoluteString] hasPrefix:#"https://accounts.google.com/o/oauth2/auth"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:ApplicationOpenGoogleAuthNotification object:url];
return NO;
}
return [super openURL:url];
}
#end
this will basically prevent anything to be opened from Chrome on iOS
we catch the auth call and redirect it to our internal UIWebView
2) to info.plist, add the Principal class, and for it Application (or whatever you named the class)
Add plist key "NSPrincipalClass" and as the value the class of your main application (class which extends UIApplication, in this case Application (see code above))
3) catch the notification and open an internal webview
When your custom Application class sends ApplicationOpenGoogleAuthNotification, listen for it somewhere (in the AppDelegate maybe) and when you catch this notification, open a UIWebView (use the URL passed by the notification as the url for the webview) (in my case the LoginViewController listens for this notification and when received, it opens a view controller containing only a webview hooked up to delegate)
4) inside the webview
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([[[request URL] absoluteString] hasPrefix:#"com.XXX.XXX:/oauth2callback"]) {
[GPPURLHandler handleURL:url sourceApplication:#"com.google.chrome.ios"n annotation:nil];
// Looks like we did log in (onhand of the url), we are logged in, the Google APi handles the rest
[self.navigationController popViewControllerAnimated:YES];
return NO;
}
return YES;
}
or simmilar code, that handles the response
com.XXX.XXX:/oauth2callback from code above, replace with your company and app identifier, like "com.company.appname:/oauth2callback"
you might want to use #"com.apple.mobilesafari" as sourceApplication parameter
So, it depends what you want to do.
Sign-In: this will always call out to another application. If the Google+ application is installed it will call out to that, else it will fall back to Chrome and Safari.
Sharing/Interactive Posts: right now this always uses Chrome or Mobile Safari.
Retrieving friends, writing app activities, retrieving profile information: All this is done with the access token retrieved after sign in, so does not require leaving the application.
It is possible, though rather unsupported, to skip the SDK and pop up a UIWebView, construct the OAuth link dynamically and send the user to that (take a look at GTMOAuth2ViewControllerTouch in the open source libraries that ship with the SDK). Below is the a very rough example of the kind of thing you could do to plumb it back into the GPPSignIn instance.
However, you would be guaranteeing that the user has to enter their username and password (and maybe 2nd factor). With the Google+ app you're pretty much guaranteed to be already signed in, and with the Chrome/Safari route, there is a chance the user is already signed in (particularly if they're using other apps with Google+ Sign-In).
This also doesn't address sharing, so I would strongly recommend using the existing SDK as far as possible. Filing a feature request for the way you would prefer it to work would be a good thing to do as well: https://code.google.com/p/google-plus-platform/issues/list
#interface ViewController() {
GTMOAuth2ViewControllerTouch *controller;
}
#end;
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.clientID = #""; // YOUR CLIENT ID HERE.
signIn.delegate = self;
}
- (IBAction)didTapSignIn:(id)sender {
void (^handler)(id, id, id) =
^(GTMOAuth2ViewControllerTouch *viewController,
GTMOAuth2Authentication *auth,
NSError *error) {
[self dismissViewControllerAnimated:YES completion:^{
[controller release];
}];
if (error) {
NSLog(#"%#", error);
return;
} else {
BOOL signedIn = [[GPPSignIn sharedInstance] trySilentAuthentication];
if(!signedIn) {
NSLog(#"Sign In failed");
}
}
};
controller = [[GTMOAuth2ViewControllerTouch
controllerWithScope:kGTLAuthScopePlusLogin
clientID:[GPPSignIn sharedInstance].clientID
clientSecret:nil
keychainItemName:[GPPSignIn sharedInstance].keychainName
completionHandler:handler] retain];
[self presentViewController:controller animated:YES completion:nil];
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (!error) {
UIAlertView * al = [[UIAlertView alloc] initWithTitle:#"Authorised"
message:#"Authorised!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[al show];
[al release];
}
}
The only real trick to this code is that it uses the [GPPSignIn sharedInstance].keychainName - this means that the auth tokens get stored in the same keychain entry as the GPPSignIn button would, which in turn means we can use [[GPPSignIn sharedInstance] trySilentAuthentication] once it has been populated, and keep the same callback based flow as the main library.
#PeterLapisu approach works good if the Google Plus App is not installed.
Then outgoing url prefixes from app are as follows:
#"googlechrome-x-callback:"
#"https://accounts.google.com/o/oauth2/auth"
However if the Google App is installed there is one more outgoing url and the prefix list looks as follows:
#"com.google.gppconsent.2.4.1:"
#"googlechrome-x-callback:"
#"https://accounts.google.com/o/oauth2/auth"
So, if the Google App is installed, it will be launched simultaneously with our app UIViewController that contains webview.Then if user sucessfully logs in with Google App he will be directed back to our app and the ViewController will be visible.
To prevent this Google App should be allowed to login user and direct him back to our app. According to this discussion: https://code.google.com/p/google-plus-platform/issues/detail?id=900 it is allowed by Apple.
So in my implementation firstly I am checking if the Google App is installed:
- (BOOL)openURL:(NSURL*)url {
NSURL *googlePlusURL = [[NSURL alloc] initWithString:#"gplus://plus.google.com/"];
BOOL hasGPPlusAppInstalled = [[UIApplication sharedApplication] canOpenURL:googlePlusURL];
if(!hasGPPlusAppInstalled)
{
if ([[url absoluteString] hasPrefix:#"googlechrome-x-callback:"]) {
return NO;
} else if ([[url absoluteString] hasPrefix:#"https://accounts.google.com/o/oauth2/auth"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:ApplicationOpenGoogleAuthNotification object:url];
return NO;
}
}
return [super openURL:url];
}
EDIT:
Now I can confirm that my app was finally approved with this solution.
I hope it will help somebody.
It merges Google+ and Gmail samples and completely avoids using Google SignIn Button, i.e you do not leave the app.
Add both Google+ and Gmail API to you Google project, in your app login to google as you would to gmail using GTMOAuth2ViewControllerTouch.xib from OAuth2 and set scope to Google+:
-(IBAction)dologin{
NSString *scope = kGTLAuthScopePlusLogin;//Google+ scope
GTMOAuth2Authentication * auth = [GTMOAuth2ViewControllerTouch
authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:kClientSecret];
if ([auth refreshToken] == nil) {
GTMOAuth2ViewControllerTouch *authController;
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:scope
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
[[self navigationController] pushViewController:authController animated:YES];
}else{
[auth beginTokenFetchWithDelegate:self didFinishSelector:#selector(auth:finishedRefreshWithFetcher:error:)];
}
}
and RETAIN the authentication object if signed in successfully, then use that auth object when using google plus services:
GTLServicePlus* plusService = [[[GTLServicePlus alloc] init] autorelease];
[plusService setAuthorizer:self.auth];//!!!here use our authentication object!!!
No need for GPPSignIn.
Full write up is here: Here is Another Solution
Use the (new) Google Sign In iOS SDK.
The SDK natively supports Sign In through WebView when no Google app is present to complete the Sign In process. It also supports potential dispatch to several Google apps for this purpose.

iOS 6 Social framework not going to settings or no alert

I'm trying to implement the new social framework in iOS6, and have it working, except for 2 weird problems. If I've enabled the services I'm interested in (say... FaceBook), then it works fine. However, if the accounts are deleted from the settings panel (let's say FaceBook, to be consistent), then I get differing, and frustrating behaviors in the simulator and the device.
Here's the relevant code in my view controller:
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
//check to see if facebook account exists
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
}
And here's the weird behavior when firing off the above method:
In the simulator (version 6.0 (358.4) I get the dialog informing me that I haven't set up any faceBook accounts with "Settings" and "Cancel" buttons. Hitting "Settings" just dismisses the dialog, but doesn't take me to the settings panel.
On my iPhone 4s running 6.01, hitting the button that triggers the method results in... nothing. In other words, I get no dialog informing me that I have to set up a FaceBook account.
Thanks in advance for your help.
OK... Here's the fix:
Here's my new implementation, based on user1734802's helpful comment.
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
At some point I expect
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
to actually work correctly (triggering the automatic dialog, and taking you to settings), so I actually just commented it out in my code.
I had the same problem, i fixed it by removing the If statement:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
Then the view will display although there is no Facebook/Twitter account configured in the settings.
And the "No Facebook/Twitter accounts" alertView showed! And I was able to hit the "Settings" button on the alert, and it directed me to the settings (Configure Facebook/Twitter account in the settings)
This is the code I used, and it works perfectly for me:
- (IBAction)bTwitter:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:#""];
[mySLComposerSheet addImage:[UIImage imageNamed:#""]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}

UIDocumentInteractionController no longer works in iOS6

I have an app that shares with instagram built for iOS5 and now in iOS6, sharing no longer works although canOpenURL returns true and code executes. The images are saved to the documents folder of the application with a .igo extension. This is passed to instagram with com.instagram.exclusivegram.
The code is below, it enters the if statement and displays "here in" but does not open the Share With dialog like it used to at the bottom of the screen.
NSLog(#"%#", _imgToUpload);
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
uidController = [[UIDocumentInteractionController alloc] init];
//imageToUpload is a file path with .igo file extension
uidController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:_imgToUpload]];
uidController.UTI = #"com.instagram.exclusivegram";
uidController.delegate = self;
CGRect navRect = self.view.frame;
[uidController presentOpenInMenuFromRect:navRect inView:[UIApplication sharedApplication].keyWindow animated:YES];
NSLog(#"here in");
}
_imgToUpload is providing the correct filepath as well.
Thank you,
Nick
Just did some testing and found a solution. Do not present in the keyWindow.
[uidController presentOpenInMenuFromRect:navRect inView:self.view animated:YES];
I have tested this and it will fix the problem.
Another reason for the uidocumentinteraction controller not working in iOS6 is that the new action sheet/launch panel (it shows apps available to open the doc) is now used. My app which worked fine launching iBooks with iOS5 failed because I launched from viewDidLoad which was now too early and I got an error on the current view controller 'whose view is not in the window hierarchy' so I changed my code to performselector after delay of 1 second. The app now calls iBooks via the new panel.

How can I improve my TWTweetComposeViewController code in iOS?

I have implemented the following code to do a Twitter Share. In my code I try to test for iOS 5 and if that does not work, I go back to the old way of sharing using ShareKit's Twitter code.
I showed the code to a co worker and he suggested that my code may have flaws and that I need to do two things:
Do a proper Run Time check?? (since it may crash on IOS 4 and earlier) EVEN though it did not.
Weak Link the Twitter frame work
Can someone kindly explain what a proper run time check would be? and Why Weak Link?
NSString *text = [NSString stringWithFormat:#"#Awesome chart: %#", self.titleLabel.text];
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetComposeViewController = [[TWTweetComposeViewController alloc] init];
[tweetComposeViewController setInitialText:text];
[tweetComposeViewController addImage:image];
[tweetComposeViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result){
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissModalViewControllerAnimated:YES];
if (result == TWTweetComposeViewControllerResultDone)
{
NSLog(#"iOS 5 onwards Twitter share complete");
}
});
}];
[self presentViewController:tweetComposeViewController
animated:YES
completion:^{ }];
}
else
{
SHKItem *item = [SHKItem image:image title:text];
// Share the message.
[SHKTwitter shareItem:item];
NSLog(#"Device does not support Twitter library");
}
}
A weak link simply means the a framework is not required to be on the device. Or put another way, when you add frameworks to your project, the app will require that framework to be on the device. So if you require a framework to be there, and it isn't, then the app will crash. In your case, you would want to weak link the twitter framework if you want the app to run on iOS version prior to iOS 5 (ie iOS 4.x).
A proper run time check means you should load the app onto your device (running iOS 5 or later) and test the twitter feature of your app. If it crashes, then you know you have a problem.
I skimmed your code and everything looks fine. I didn't run it through my complier though so I can't speak for syntax errors and such. The one change I would make is:
if ([TWTweetComposeViewController canSendTweet])
to
Class twClass = NSClassFromString(#"TWTweetComposeViewController");
if (!twClass) // Framework not available, older iOS
return;
The reason why I use that is becuase that literally checks if the framework is on that device, while canSendTweet checks if the user is logged in. So I don't want to confuse a user not being logged in with a user whose device doesn't support Twitter with iOS 5.
Let me know if you need anymore help.
DETweetComposeViewController is another option. It's compatible with iOS 4 too.
I think you also leak the controller (as do most of the code samples I've seen).
On the other hand, you paid attention to the documentation about the completion handler, and correctly make sure you do UI work in the main thread. I need to go fix my implementation to do the same.