Facebook iOS SDK 3.22.0 - FBGraphUser - missing its native class

Just ported a project to handle 64 bits and updated facebook component to Facebook iOS SDK 3.22.0.

The code that was previously working it does not work properly anymore. We had this:

FBRequest request;
FBRequestConnection requestConnection = request.Start ((connection, result, err) => {
                ...
using (var user = new FBGraphUser (result.Handle)) {

}

this constructor is now protected.

Despite that,

If we try this

using (var user = new FBGraphUser ()) {

}

we get the following error

Wrapper type 'MonoTouch.FacebookConnect.FBGraphUser' is missing its native ObjectiveC class 'FBGraphUser'.

I was trying to search for the source of this project but did not find it. Any ideas of what is happening?

tkx

Posts

  • ManuelCostaManuelCosta PTMember ✭✭

    Just forgot to mention that the component that we are using

    facebookios

  • JanDrykJanDryk USMember
    edited January 2015

    The solution is to use Runtime.GetNSObject(handle)

    "The NSObject .ctor(IntPtr) constructor has been changed from public to protected (to prevent improper use)."
    http://developer.xamarin.com/guides/cross-platform/macios/updating-tips/

  • RainerMagerRainerMager JPMember ✭✭

    @ManuelCosta, did you get this to work? How? Can you share a small sample?

    @JanDryk, can you say more? I'm having a similar problem trying to create a FBOpenGraphObject. When I call new FBOpenGraphObject() I get the "missing its native ObjectiveC class" exception. In this case, where do we get the handle to pass into Runtime.GetNSObject?

    I tried the following, but it says the cast is invalid. So how can I create a FBOpenGraphObject?
    (FBOpenGraphObject)ObjCRuntime.Runtime.GetNSObject(FBGraphObject.OpenGraphObject.Handle)

  • ManuelCostaManuelCosta PTMember ✭✭

    Hi @
    yes, i have it working.
    The confusion seems to come from FBGraphUser, which can be a protocol and a class. Facebook sdk was changed overtime and FBGraphUser is bind only as a protocol.

    Here is the code that we use to access user's public data

    hope it helps

    cheers
    Manuel

    `

    public class FacebookData
    {
        NSString firstNameKey = new NSString ("first_name");
        NSString lastNameKey = new NSString ("last_name");
        NSString birthdayKey = new NSString ("birthday");
        NSString idKey = new NSString ("id");
        NSString linkKey = new NSString ("link");
        NSString emailKey = new NSString ("email");
        NSString genderKey = new NSString ("gender");
        NSString localeKey = new NSString ("locale");
        NSString updated_timeKey = new NSString ("updated_time");
        NSString verifiedKey = new NSString ("verified");
        NSString timezoneKey = new NSString ("timezone");
        private string[] ExtendedPermissions = new [] {"user_about_me"};
        private bool facebookUserInfoRequested = false;
    
        public void GetFacebookInfo()
        {
            if(FBSession.ActiveSession.State == FBSessionState.CreatedTokenLoaded){
                bool result = FBSession.OpenActiveSession(false);
    
                if (!result) {
                    result = FBSession.OpenActiveSession (ExtendedPermissions, true, new FBSessionStateHandler (HandleFacebookSessionStateChanged));
                }
                else {
                    HandleFacebookSessionStateChanged (FBSession.ActiveSession, FBSession.ActiveSession.State, null);
                }
            }
            else if (FBSession.ActiveSession.State == FBSessionState.Open || FBSession.ActiveSession.State == FBSessionState.OpenTokenExtended)
            {
                HandleFacebookSessionStateChanged (FBSession.ActiveSession, FBSession.ActiveSession.State, null);
            }
            else 
                FBSession.OpenActiveSession(ExtendedPermissions, true, new FBSessionStateHandler(HandleFacebookSessionStateChanged));
        }
    
    
        void HandleFacebookSessionStateChanged(FBSession s, FBSessionState status, NSError error)
        {
            if (status == FBSessionState.Open || status == FBSessionState.OpenTokenExtended) 
            {
                //if (!facebookUserInfoRequested) 
                {
                    FBRequest request = FBRequest.ForMe;
    
                    FBRequestConnection requestConnection = request.Start ((connection, result, err) => {
                        try 
                        {
                            if (err != null) 
                            {
                                //##########Removed code
                                return;
                            }
    
                            InsertUserInfo (result as FBGraphObject, result.Description);
    
                        } 
                        catch (Exception ex) 
                        {
                            //##########Removed code
                        }
                    });
                }
            } 
        }
    
        private string GetInfo(FBGraphObject user, string key){
            var field = user [key];
    
            if (field != null)
                return field.ToString ();
            else
                return null;
        }
    
        void InsertUserInfo(FBGraphObject user, string raw){
            UserInfoDB userInfo = new UserInfoDB ();
    
            userInfo.UserInfoId = GetInfo(user, idKey);//.GetId ();
            userInfo.Birthday = GetInfo(user, birthdayKey);//.GetBirthday ();
            userInfo.First_Name = GetInfo(user, firstNameKey);//.GetFirstName ();
            userInfo.Last_Name = GetInfo(user, lastNameKey);//.GetLastName ();
            userInfo.Link = GetInfo(user, linkKey);//.GetLink ();
            userInfo.EMail = GetInfo(user, emailKey);
            userInfo.Gender = GetInfo(user, genderKey);
            userInfo.Locale = GetInfo(user, localeKey);
            userInfo.Timezone = GetInfo(user, timezoneKey);
            userInfo.Updated_time = GetInfo(user, updated_timeKey);
            userInfo.Verified = GetInfo(user, verifiedKey);
    
            userInfo.Source = (int)UserInfoSource.Facebook;
            userInfo.Reserved1 = raw;
            userInfo.Timestamp = DateTime.UtcNow;
    
    
            //##########Removed code
        }
    
    
    
    }
    

    `

  • ManuelCostaManuelCosta PTMember ✭✭

    Forgot AppDelegate

    we also have this in AppDelegate

        public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
        {
            if (FBSession.ActiveSession != null) {
                // We need to handle URLs by passing them to FBSession in order for SSO authentication
                // to work.
                return FBSession.ActiveSession.HandleOpenURL (url);
            } else {
                return base.OpenUrl (application, url, sourceApplication, annotation);
            }
        }
    
        public override void OnActivated (UIApplication application)
        {
            // We need to properly handle activation of the application with regards to SSO
            // (e.g., returning from iOS 6.0 authorization dialog or from fast app switching).
            if (FBSession.ActiveSession != null) {
                FBSession.ActiveSession.HandleDidBecomeActive ();
            }
        }
    
  • TonyFonagerTonyFonager DKInsider ✭✭

    Thanks, just what I was looking for ;-)

Sign In or Register to comment.