共享有针对性的xamarin表单

时间:2017-08-31 18:05:21

标签: xamarin

我使用以下命令共享链接,但是使用此命令打开一个包含应用程序供我分享的框。我希望当我分享它已经直接进入Facebook,而不通过这个框

    void OnTapped4(object sender, EventArgs args)
    {
        CrossShare.Current.ShareLink(link, "teste", titulo);
    }

需要直接分享到Facebook,whatsapp,twitter和电子邮件


我有这个命令加上它只适用于xamarin android,在xamarin表单中它不起作用

Intent sendIntent = new Intent();
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText,"titulo");
sendIntent.SetType("text/plain");
sendIntent.SetPackage("com.facebook.orca");
StartActivity(sendIntent);

1 个答案:

答案 0 :(得分:0)

我找到了以下示例,我在android上做了它并且它有效,现在我想在IOS中这样做我怎么能让它去whatsapp

的Android

public class ShareService : IShareService
{
    public void SharePageLink(string url)
    {
        var context = Forms.Context;
        Activity activity = context as Activity;

        Intent share = new Intent(Intent.ActionSend);
        share.SetType("text/plain");
        share.AddFlags(ActivityFlags.ClearWhenTaskReset);
        share.PutExtra(Intent.ExtraSubject, "Brusselslife");
        share.SetPackage("com.whatsapp");
        share.PutExtra(Intent.ExtraText, url);


        activity.StartActivity(Intent.CreateChooser(share, "Share link!"));
    }
}

在IOS中放置这个'com.whatsapp'

public class ShareService : IShareService
{
    public void SharePageLink(string url)
    {
        var window = UIApplication.SharedApplication.KeyWindow;
        var rootViewController = window.RootViewController;

        //SetPackage

         var activityViewController = new UIActivityViewController(new NSString[] { new NSString(url) }, null);

        activityViewController.ExcludedActivityTypes = new NSString[] {
            UIActivityType.AirDrop,
            UIActivityType.Print,
            UIActivityType.Message,
            UIActivityType.AssignToContact,
            UIActivityType.SaveToCameraRoll,
            UIActivityType.AddToReadingList,
            UIActivityType.PostToFlickr,
            UIActivityType.PostToVimeo,
            UIActivityType.PostToTencentWeibo,
            UIActivityType.PostToWeibo
        };

        rootViewController.PresentViewController(activityViewController, true, null);
    }
}