Reputation: 980
I making a social application which requires Google+. I know that I can open Google+ as a link to Safari (Which isn't really user Friendly having to switch apps just to post something). This code opens the link to Safari:
-(IBAction)Google+:(id)sender {
NSLog(@"Google+");
//The link will go to Stack Overflow Google+ Page
NSURL *GooglePlus = [NSURL URLWithString:@"https://plus.google.com/+StackExchange/posts"];
[[UIApplication sharedApplication] openURL:GooglePlus];
}
But is there a way to detect if Google+ Application is installed and open the application there (And if it isn't then open the link to Safari). I thank Everyone who take the time to read my post (Even if you didn't) :)
Upvotes: 2
Views: 1902
Reputation: 443
In Xcode 6 and Swift, you can write:
let gplusURL = "gplus://your url"
if UIApplication.sharedApplication().canOpenURL(NSURL.URLWithString(gplusURL)){
UIApplication.sharedApplication().openURL(NSURL.URLWithString(gplusURL))
}
else{
var alertView = UIAlertView()
alertView.addButtonWithTitle("OK")
alertView.title = "HEY"
alertView.message = "It seems Google Plus is not installed on your device"
alertView.delegate = self
alertView.show()
Upvotes: 0
Reputation: 1190
Now you are able to launch Google+ app using next protocol:
gplus://
For example
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gplus://"]];
UPD: So, to launch any page in G+ app you just need to change https:// in URL on gplus://, for example this will launch user profile:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gplus://plus.google.com/u/0/105819873801211194735/"]];
Upvotes: 7