- Home /
How do apps post on walls without the actual login flow?
Some games like Crossy roads bring up the share dialog from facebook without actually ever having to redirect to fb app for permissions. How is this possible? Also how can you get the native iOS dialog that slides up when you want to share with options like "message/mail/fb/twitter" etc. Any insight on this is appreciated. Thanks!
Answer by callen · Dec 29, 2015 at 07:36 PM
At some point you'll need to log in to use FB integration, but I'm guessing the FB SDK is able to save the fact that you logged in, so every app you authorize doesn't need to be individually logged into. I hear that today the only way to do any facebook interaction from an app is their SDK, which kinda sucks for app devs.
The non-FB sharing stuff is completely different, and platform-dependent. There are asset store packages for this, however the code is not very difficult.
I made iOS and Android plugins to do this stuff in about a day or two (half of that learning the ridiculous Obj-C syntax). It does involve a lot of pieces though, so instead of trying to dump a bunch of code here I'll tell you where to start your searches.
iOS
UIActivityViewController* activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postItems applicationActivities:nil];
[[[UIApplication sharedApplication] keyWindow].rootViewController
presentViewController:activityVC animated:YES completion:nil];
Here, the main data variable is "postItems" which contains some text and an image. A lot of NSString headaches here though... basically, what you need to worry about here is getting the data between Objective-C and Unity.
Android Actually, I lied here and didnt make it a plugin. Instead I used Unity's JNI methods to call the few things I needed to do.
readonly AndroidJavaObject CurAct = (new AndroidJavaClass("com.unity3d.player.UnityPlayer")).GetStatic<AndroidJavaObject>("currentActivity");
readonly AndroidJavaClass IntentClass = new AndroidJavaClass("android.content.Intent");
public void ShareMessage(string message)
{
Debug.Log("Android share text=" + message);
var intent = buildShareIntent(message, null);
presentWithChooser(intent);
}
void presentWithChooser(AndroidJavaObject intent)
{
var shareChooser = IntentClass.CallStatic<AndroidJavaObject>("createChooser", intent, "Share...");
CurAct.Call("startActivity", shareChooser);
}
AndroidJavaObject buildShareIntent(string message, AndroidJavaObject uri)
{
AndroidJavaObject newIntent = new AndroidJavaObject("android.content.Intent", Intent_ACTION_SEND);
//Set content type based on whether or not we got a URI
newIntent.Call<AndroidJavaObject>("setType", uri == null ? MIME_TEXT : MIME_IMAGE);
//Add the message and/or image data
if (uri != null) newIntent.Call<AndroidJavaObject>("putExtra", Intent_EXTRA_STREAM, uri);
if (!string.IsNullOrEmpty(message)) newIntent.Call<AndroidJavaObject>("putExtra", Intent_EXTRA_TEXT, message);
return newIntent;
}
Notice that my buildShareIntent has a URI parameter? That's how I post an image, but dealing with the required file-permission stuff needed is beyond the scope of this response.
I'll just add this because it held me up a lot: to use a "FileProvider" you need an xml defining its path, and put that file at Assets/Plugins/Android/res/xml/myFileProviderPaths.xml, which you reference in your android manifest as android:resource="@xml/myFileProviderPaths". The details of all this are extensively covered on the web / S.O. as its a core part of Android app sharing.
Good luck!
Thanks a lot for the detailed explanation and the code examples. I have never developed unity plugins before, but will definitely look into it.
Answer by ARKMs · Dec 29, 2015 at 07:36 PM
I recommend these two plugins:
https://github.com/is8r/unity-SocialPostPlugin This can share text without using the SDK or application of Facebook and Twitter, this use the integration that already contains iOS since version 6.0
https://github.com/ChrisMaire/unity-native-sharing And This, is for share text or screenshot With dialog share in iOS and Android
Wish I had seen these before I built my own <_< but oh well I probably wouldn't understand them if not for doing it myself.
@AR$$anonymous$$$$anonymous$$'s thanks a ton for linking these unity plugins. This is what I was looking for!
Answer by ArshakKroyan · Dec 30, 2015 at 04:29 AM
Hi. Here is a good tutorial for sharing. http://www.theappguruz.com/blog/general-sharing-in-android-ios-in-unity
For more information you can search "IOS share Activity ".
Your answer
Follow this Question
Related Questions
Facebook share for Webplayer. 2 Answers
Social media assets 1 Answer
Unity Facebook Invitation Notification? 0 Answers
Post to Facebook app using Application.OpenURL()? 1 Answer
Post Score to Facebook IOS 1 Answer