2

So I've got some twitter integration in my app, and it's a bit buggy - if the app is installed the twitter site still launches inside my app.

So I was wondering if it's possible to do something like this from within a Phonegap app:

// check whether facebook is (likely to be) installed or not
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
    // Safe to launch the facebook app
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/200538917420"]];
}

The code that I've currently got that launches Twitter is:

var then = (new Date()).getTime();
var msg = encodeURIComponent("My Message");
window.open('twitter://post?message='+msg);
setTimeout(function(){
    var now = (new Date()).getTime();
    if((now - then)<400){
        window.open('http://twitter.com/?status='+msg, '_system');
    }
},300);
Community
  • 1
  • 1
ahren
  • 16,803
  • 5
  • 50
  • 70

1 Answers1

0

I suggest you use one of this solutions.

1.Add social sharing phonegap plugin

https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin

OR

2.Add this line of codes into your MainViewController.m before @end

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];

    // Intercept the external http requests and forward to Safari.app
    // Otherwise forward to the PhoneGap WebView
    if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]){
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
    }
}
Nurdin
  • 23,382
  • 43
  • 130
  • 308