I’m trying to call the oficial facebook App from my game instead open the safari browser. When the user click on my facebook button, I want to redirect him to my facebook page using the facebook oficial app.
But what if the user does not have the facebook application installed?
So, I tried this one:
void OpenFacebookPage ()
{
WWW www = new WWW("fb://page/xxxxx");
StartCoroutine(WaitForRequest(www));
}
IEnumerator WaitForRequest(WWW www)
{
yield return www;
// check for errors
if (www.error == null)
{
Debug.Log("Sucess!: " + www.text);
}
else
{
Debug.Log("WWW Error: "+ www.error + " Opening Safari...");
//error. Open normal address
Application.OpenURL ("http://www.facebook.com/xxxxxx");
}
}
But it did not work as I expected - always return error. I guess it did not work because WWW not support the facebook protocol. In the Unity scripting reference:
Note: http://, https:// and file:// protocols are supported on iPhone. ftp:// protocol support is limited to anonymous downloads only. Other protocols are not supported.
So, I’m stucked here… Anyone knows how to solve this?
This worked like a charm for me. One thing to note – while my page’s address is Redirecting..., fb://page/CakeDayApp didn’t work when I tested the links in email. On fb, go to your page, click edit page>update info and in the url bar grab the digits after id= and use those for the fb:// link
Probably do nothing. You can try waiting a second or two and do a normal OpenUrl to safari as a fallback option.
edit: sorry, didn’t read your OP fully. Yeah, I doubt WWW would be of any use for opening a custom URL scheme because it’s not doing any network requests. It’s just telling the OS to open an app with that URL id. As far as I know, the OS doesn’t send back a message if it fails so I’d just wait a second or two and open the url in safari.
yes, that is what I’m trying to do. But I need to test if the first link have worked, and the only way I found is using WWW form. But WWW always return error because it does not support the facebook protocol. (fb://).
hum, I think it will open the facebook app, then when the game did become active again, it will open the safari… You will have a double call for those who have the facebook app.
edit: If anybody uses this code, you may want to make tweaks to handle instances where the user taps the button multiple times before the app is able to switch over
Do you happen to know if this code works on Android as well? It seems like it would; I’ll report back if I hear nothing, because I’ll have to get this working soon anyway!
So, it seems like this is broken in Facebook’s new native app. fb://page/315797608481737 doesn’t work. fb://page/CakeDayApp doesn’t work. Any ideas?
edit: fb://profile/315797608481737 works.
Also, I found a tutorial that mentions what seems to be a cleaner way (through native objC) to fallback to safari if they don’t have the app, but I haven’t tried it yet
I’ll have to fix it in the next update because these link is in the code. Are you using an external server to get this link in your games and be able to change it anytime?
So I’m trying out the solution JTown has posted on my Android project, but it causes Unity to crash if fb:// is called and Facebook isn’t installed on the device. Same problem with trying to call twitter:// for Twitter. If the apps are installed though it works fine. Any thoughts?
Android reports this crash:
E/AndroidRuntime(30849): FATAL EXCEPTION: GLThread 2783
E/AndroidRuntime(30849): android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=android.intent.action.VIEW dat=twitter://user?scree
n_name=HandyArtTool }