在Xcode 4.5中打开Google+ Application



我在做一个需要Google+的社交应用。我知道我可以打开Google+作为Safari的链接(这不是真正的用户友好切换应用程序只是为了发布一些东西)。下面的代码打开到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];        
 }

但是是否有一种方法可以检测是否安装了Google+应用程序并在那里打开应用程序(如果没有,则打开到Safari的链接)。我感谢每一个花时间阅读我的帖子的人(即使你没有):)

现在您可以使用下一个协议启动Google+应用程序:

gplus://

例如

[[UIApplication sharedApplication] openURL:[NSURL . cnURLWithString: @"gplus:公关//"]],

乌利希期刊指南:所以,要在gplus应用程序中启动任何页面,你只需要在gplus://的URL中更改https://,例如,这将启动用户配置文件:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gplus://plus.google.com/u/0/105819873801211194735/"]];

根据这篇文章,不可能在另一个应用程序中运行应用程序,但可以启动任何注册URL Scheme的应用程序。您应该检查Google+ Application是否属于这种情况。

编辑Google+似乎不在名单上:-(

)

在Xcode 6和Swift中,你可以这样写:

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

相关内容

最新更新