How do I launch Twitter app instead of Safari en iOS

I’m trying the code here
http://forum.unity3d.com/threads/143623-Open-facebook-app-instead-safari-iOS-C?p=982528&viewfull=1#post982528

But it launches the app, and not the link, I mean, it doesn’t take me to the profile I’m giving it
I’ve tried
twitter://3d_avenue
and twitter://www.twitter.com/3davenue but it doesn’t work.

The facebook one worked, using Application.OpenURL(“fb://profile/289896607788470”); and Application.OpenURL(“Redirecting...”); in case it fails, but I can’t get it to work for Twitter.

Any suggestions? Thanks!

(Not tested)
Application.OpenURL(twitter://…);

http://wiki.akosma.com/IPhone_URL_Schemes#Twitter

Application.OpenURL(“twitter://3D_Avenue”); doesn’t work though. It launches the app but not to the profile, just wherever it was the last time it was used.

twitter:///user?screen_name=username

works for me. Replace username

Just did that, it works perfect, thanks!

I use a co-routine. Not my idea, I got it from a thread, but don’t have the link.

void OnApplicationPause(bool inIsPause)
{
   this.mIsAppLeft = true;
}

IEnumerator OpenFacebook()
{
    Application.OpenURL("fb://profile/################");//replace #'s w/ fb profile id
    yield return new WaitForSeconds(1f);
    if (this.mIsAppLeft)
         this.mIsAppLeft = false;
    else
        Application.OpenURL("http://www.facebook.com/mypage");//replace mypage
}

IEnumerator OpenTwitter()
{
    Application.OpenURL("twitter:///user?screen_name=username");//repace username
    yield return new WaitForSeconds(1f);
    if (this.mIsAppLeft)
        this.mIsAppLeft = false;
    else
        Application.OpenURL("http://www.twitter.com/username");//replace username
}

I get this error

Assets/Resources/Scripts/Menu/TwitterButton.cs(28,9): error CS1061: Type TwitterButton' does not contain a definition for mIsAppLeft’ and no extension method mIsAppLeft' of type TwitterButton’ could be found (are you missing a using directive or an assembly reference?)

I have this code, but I have a weird issue, if it takes too long to open, or if I don’t have Twitter on my recent apps, it launches Twitter, but after a couple of seconds, it launches Safari with the link.

If I do however have the Twitter app on my recents, it launches correctly.

What should I do? Here’s the code.

void OnClick() {
		
		Debug.Log("called ngui twitter function");
		float startTime;
		startTime = Time.timeSinceLevelLoad;

        //open the twitter app
        Application.OpenURL("twitter:///user?screen_name=3D_Avenue");
			
		if (Time.timeSinceLevelLoad - startTime <= 1f)
		{	
			//fail. Open safari.
			Application.OpenURL("http://www.twitter.com/3D_Avenue");
		}
	}

I tried changing the time comparison (the 1f) to 10f, but it didn’t really help on an iPhone 4, on which Twitter takes like 15 seconds to launch, I wondered if I could avoid using a timer for this, nocanwin’s solution seems to be similar on this regard, but I wasn’t able to test it because of the error I get mentioned on my previous post.

Thanks, this is what I needed :slight_smile: