Sharing contents in Twitter and Facebook

MAIN DIFFERENCES SHARING IN ANDROID, IOS AND WINDOWS DEVICES

We’ve recently started to work on researching paths in mobile development that are very common in these days in order to master them and, at the same time, find the differences on the currently most used platforms: Android, iOS and Windows 8.1 (Universal).

As a small snippet, here we bring an article about sharing contents on social networks.

IOS

(by REBECA MARTÍN DE LEÓN)

In iOS platform we are using Social framework, the native one; in this way we are going to show the default view controllers:

facebook twitter

 

SLComposeViewController class must be used, setting the service type.

At the beginning it is necessary to check if those services are available in device Settings module:

if SLComposeViewController.isAvailableForServiceType(serviceType) {}

Where serviceType will be:

  • SLServiceTypeFacebook (Facebook), or
  • SLServiceTypeTwitter (Twitter).

So, if the user has already registered a Twitter/Facebook account in Settings, he/she will be able to publish a message into these social networks. If those services are not available, we manage it to show an error message about the necessity to register social network accounts to publish.

If the service is available, show the social view:

var socialViewController:SLComposeViewController = SLComposeViewController(forServiceType: serviceType)

It is possible to complete the socialViewController with some parameters as an initial message:

socialViewController.setInitialText(initialText)

In the samples above: I’m sharing with Facebook/Twitter in this sample app

Or an image:

socialViewController.addImage(UIImage(named:imageName))

Ready! This way we can easily include sharing in social networks in your iOS app.

As always, creating a module to manage this is a recommended work.

ANDROID

(by JOSÉ CARLOS MONTES MARTOS)

Facebook

WARNING:

We have tried sharing content to facebook using Android intents, but content was not retrieved by Facebook app. That is, we launched intents to share with facebook but those texts or images were not being received by Facebook App.

After looking into this issue, we have found that Facebook stop supporting this fact due to its privacy as reflected in this bug  https://developers.facebook.com/bugs/332619626816423

So, the only way to share was using the Facebook SDK.

Using Facebook SDK (https://developers.facebook.com/docs/android):

  • Facebook App is not needed to be installed.
  • Log in is required and you have to request permission for publishing before first use.

Twitter

Twitter is more flexible than Facebook for sharing. It lets you share content using either Intents or its SDK.

Using Intents

  • Requirement: app must be installed (of course!)

Using SDK (https://dev.twitter.com/twitter-kit/android)

  • Requirement: You need to register your app in fabric.io.
  • Twitter app is not mandatory.
    • If Twitter app is not installed, a web view will be launched.
    • Else, without leaving your app, it will use your twitter account in order to publish tweet using a dialog as it appears in the Twitter app
TweetComposer.Builder builder = new TweetComposer.Builder(getActivity()).text("Sharing with Twitter SDK");

WINDOWS UNIVERSAL

(by FERNANDO DE FRANCISCO CANO)

As from Windows 8.1 and Windows Phone 8.1 universal apps are available, we’re taking advantage of it to create applications for 2 different platforms using the same code.

Microsoft platform supports sharing contents from the O.S. itself, so when running an application you only have to ask the system to share some contents and it will ask to each of the Content Listeners if they can handle the content you’re trying to share (text, image, url, etc…) The O.S. will show then a list of available content targets and the user only has to select which one to use.

Translating this to code you have to retrieve the DataTransferManager object for current view and add a trigger for DataRequested event:

DataTransferManager dataTransferManager;

dataTransferManager.DataRequested += new Windows.Foundation.TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.ShareTextHandler);

and then write down this method where we create a DataPackage to store the contents to be shared and assign it to a DataRequest object

public void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e)

{

   DataRequest request = e.Request;

   dataPackage.Properties.Title = Title;

   dataPackage.Properties.Description = Description;

   dataPackage.SetWebLink(new Uri(URI));


   request.Data = dataPackage;
}

 

Windows 8.1: Using the Charms bar option to share will show a new option when the application is in foreground.

Windows Phone 8.1: The sharing action must be manually triggerered

Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();

Leave a Comment

Responsable » Solidgear.
Finalidad » Gestionar los comentarios.
Legitimación » Tu consentimiento.
Destinatarios » Los datos que me facilitas estarán ubicados en los servidores SolidgearGroup dentro de la UE.
Derechos » Podrás ejercer tus derechos, entre otros, a acceder, rectificar, limitar y suprimir tus datos.

By completing the form you agree to the Privacy Policy

¿Necesitas una estimación?

Calcula ahora