Open Google+ Application in Xcode 4.5

2019-05-24 10:44发布

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) :)

3条回答
时光不老,我们不散
2楼-- · 2019-05-24 11:16

According to this post it is not possible to run an app within another app but it is possible to launch any app that registers a URL Scheme. You should check if that's the case for the Google+ Application.

EDIT Google+ doesn't seem to be on the list :-(

查看更多
Evening l夕情丶
3楼-- · 2019-05-24 11:17

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/"]];
查看更多
Juvenile、少年°
4楼-- · 2019-05-24 11:37

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()
查看更多
登录 后发表回答