Search Unity

Error Trying To Share A Link On Facebook on iOS

Discussion in 'iOS and tvOS' started by tonOnWu, Nov 9, 2018.

  1. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    83
    Hi guys.

    I created a code for sharing a link on Facebook. My goal is to check if the user shares the link of my App on his Facebook account. If he does it, I will grant him a reward.

    The method I created to share is called "ShareFacebook". I'm using Unity Unity 2018.2.14 and Facebook SDK 7.14.0.

    The error that xCode drops is:

    2018-11-09 05:57:02.190649-0700 christmasgiftdronear[2346:632843] +[NSError fbRequiredArgumentErrorWithDomain:name:message:]: unrecognized selector sent to class 0x1d87acf80

    2018-11-09 05:57:02.314448-0700 christmasgiftdronear[2346:632843] Uncaught exception: NSInvalidArgumentException: +[NSError fbRequiredArgumentErrorWithDomain:name:message:]: unrecognized selector sent to class 0x1d87acf80

    The original code of that component is the next:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using Facebook.Unity;
    6.  
    7. public class FacebookMngr : SingletonWulum<FacebookMngr> {
    8.  
    9.     public string userFacebookAccessTokenId = "userFacebookAccessTokenId";
    10.  
    11. //    public Text userIdText;
    12.  
    13.     [SerializeField]
    14.     private Text shareFacebookRewardText;
    15.     private int shareFacebookReward = 250;
    16.  
    17.     public override void Awake()
    18.     {
    19.         base.Awake();
    20.         Debug.Log("Awake de FB");
    21.  
    22.         if (!FB.IsInitialized)
    23.         {
    24.             FB.Init(() => {
    25.                 FB.ActivateApp();
    26.             });
    27.         }
    28.         else
    29.         {
    30.             FB.ActivateApp();
    31.         }
    32.     }
    33.  
    34.     public  void Start()
    35.     {
    36.         LogIn();
    37.     }
    38.  
    39.     public void LogIn()
    40.     {
    41.         FB.LogInWithReadPermissions (null, callback: OnLogIn);
    42.     }
    43.  
    44.     private void OnLogIn(ILoginResult result)
    45.     {
    46.         //Debug.Log("Facebook logged in:" + FB.IsLoggedIn);
    47.         if (FB.IsLoggedIn)
    48.         {
    49.             AccessToken token = AccessToken.CurrentAccessToken;
    50.             PlayerPrefs.SetString ("userFacebookAccessTokenId", token.TokenString);
    51.             //Debug.Log("Token asignado:" + token.TokenString);
    52.         }
    53.         else
    54.         {
    55.             Debug.Log ("Cancel Login");
    56.         }
    57.     }
    58.  
    59.     public void CleanFacebookToken(){
    60.         PlayerPrefs.DeleteKey("userFacebookAccessTokenId");
    61.     }
    62.     public void setFacebookPlayerPrefs(string tokenUserId)
    63.     {
    64.         PlayerPrefs.SetString ("userFacebookAccessTokenId", tokenUserId);
    65.         Debug.Log("WULUM - Next Player Has been Set: " + tokenUserId);
    66.     }
    67.  
    68.     public bool isFacebookPlayerPrefsSetted() {
    69.         bool isSetted = false;
    70.         if (PlayerPrefs.HasKey ("userFacebookAccessTokenId"))
    71.             isSetted = true;
    72.         return isSetted;
    73.     }
    74.  
    75.     public string GetFacebookAccessTokenId() {
    76.         string tokenId = "";
    77.         if (PlayerPrefs.HasKey ("userFacebookAccessTokenId")) {
    78.             tokenId = PlayerPrefs.GetString ("userFacebookAccessTokenId");
    79.         }
    80.         return tokenId;
    81.     }
    82.  
    83.     public void ShareFacebook() {
    84.  
    85.         Debug.Log("WULUM - Calling ShareFacebook");
    86.  
    87.         string appUrl = "https://itunes.apple.com/us/app/saving-christmas-ar/id1317060184?mt=8";
    88.  
    89.         FB.ShareLink(
    90.             contentURL: new System.Uri(appUrl),
    91.             contentTitle: "Saving Christmas - AR",
    92.             contentDescription: "Help santa",
    93.             photoURL: new System.Uri("http://www.wulum.com"),
    94.             callback: OnShare);
    95.  
    96.         Debug.Log("WULUM - Facebook SharingLink");
    97.        
    98.     }
    99.  
    100.     private void OnShare(IShareResult result)
    101.     {    
    102.         if (result.Cancelled || !string.IsNullOrEmpty(result.Error))
    103.         {
    104.             Debug.Log ("WULUM - Sharelink on Facebook Error: " + result.Error);
    105.             UIManager.Instance.ConfirmationGotExtraCoins (0);
    106.         }
    107.         else if (!string.IsNullOrEmpty(result.PostId))
    108.         {
    109.             Debug.Log (result.PostId);
    110.             UIManager.Instance.ConfirmationGotExtraCoins (0);
    111.         }
    112.         else
    113.         {
    114.             Debug.Log ("WULUM - Share On Facebook Succeded");
    115.             UIManager.Instance.ConfirmationGotExtraCoins (shareFacebookReward);
    116.         }
    117.     }
    118. }
    But you only should focus on the method ShareFacebook. The error is on the line:

    FB.ShareLin(contentURL: new System.Uri(appUrl)...

    Thanks for any suggestions you may have.
     
  2. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    We had the same problem. Downgraded to the 7.13.0 SDK and now it works fine.
     
  3. SamuelGoldenbaum

    SamuelGoldenbaum

    Joined:
    May 21, 2017
    Posts:
    47
    Solved? Is the related FB app taken live?