- Home /
Application.OpenURL Won't Open Url With Custom String?
I am trying to use Application.OpenURL(); to open a url that on a mobile device brings up the Twitter app and will take it to the post area in Twitter and have pre set text for the user to post which is (I've just scored "points" points) but it will not open the url as long as I am trying to add my currentScorefGui.guiText.text to the string I am passing to the Application.OpenURL(); If i remove the custom GUI text it works just fine?
I had this working just find but then yesterday it just stopped working randomly and I have tried so many different methods to get it to work but as long as I am trying to pass that gui text it won't work? Also the currenScoreGui has a GUI Text game object attached to it.
public GameObject currentScorefGui;
public string currentScoreText;
void Update () {
currentScoreText = "twitter://post?text=I've%20just%20scored%20" + currentScorefGui.guiText.text + "%20points";
}
void OnMouseUp () {
Application.OpenURL(currentScoreText);
Debug.Log("Twitter Button Pressed...");
}
Answer by rxmarccall · Dec 03, 2014 at 04:34 PM
I've been having a very similar problem, was working fine then suddenly just stopped. I just found this Unity answers page that seems to be working for me though! http://answers.unity3d.com/questions/61669/applicationopenurl-for-email-on-mobile.html
Thank you very much I have figured it out and the code below is how I got $$anonymous$$e to work.
using UnityEngine;
using System.Collections;
public class TwitterButton : $$anonymous$$onoBehaviour {
const string Address = "twitter://post?text=";
public GameObject currentScorefGui;
void On$$anonymous$$ouseUp () {
string escName = $$anonymous$$yEscapeURL("I've just scored" + currentScorefGui.guiText.text + " points!");
Application.OpenURL("twitter://post?text=" + escName);
Debug.Log("Twitter Button Pressed...");
}
string $$anonymous$$yEscapeURL (string url)
{
return WWW.EscapeURL(url).Replace("+","%20");
}
}