facebook / facebook-sdk-for-unity

The facebook sdk for unity.
https://developers.facebook.com/docs/unity
Other
492 stars 257 forks source link

Crash on launch on iOS - [FBSDKGraphRequestConnection errorFromResult:request:] #208

Closed NumaNumaNuma closed 5 years ago

NumaNumaNuma commented 5 years ago

I'm using the sdk for analytics only. I'm getting rare crashes on app launch for some of our users (Unity 2018.2.19 and iOS 12.1) on 4G only (works fine on wifi). Xcode crash logs show:

image

At first I thought it was due to FB not being initialized properly but I'm using private void Awake() { if (FB.IsInitialized) { FB.ActivateApp(); } else { FB.Init(FB.ActivateApp); } } And I check that FB has been initialised before logging any analytics event.

Not sure if I'm doing something wrong or if this is a bug. Would love some feedback either way.

Thanks!

oct-test commented 5 years ago

Done. Link: https://developers.facebook.com/support/bugs/2157336311244047/

sharonreytan commented 5 years ago

Great, thanks

KylinChang commented 5 years ago

Hi @oct-test @sharonreytan , sorry for the late reply. I will investigate the issue and will reply to you as fast as possible. Do you have the same exception as Uncaught exception: NSInvalidArgumentException: +[NSError fbErrorWithCode:userInfo:message:underlyingError:]:? Can you upload a sample project if possible?

Thanks for your comments and help in this issue!

sharonreytan commented 5 years ago

@KylinChang Yeah, that is the error. I want to help you get to the issue - it happens on iOS > 12.1.4, on Facebook SDK for Unity 7.15.1. On an iPhone -ObjC solved this issue. On iPads the error persists on wifi. Some of us experienced it for cellular. It happens on load, before we get to call FB.Init(). I will upload a sample project soon. Thank you for reopening the issue

sharonreytan commented 5 years ago

https://drive.google.com/open?id=1aLdPTQyiqpCJf1bMyOGjLeOPg2D8NjZx

Sorry it's not on git. It is a simple project with a cube, particles system and Facebook SDK 7.15.1 integrated to my app ID. Notice that the Unity project is with my app's bundle name. Change it as you wish. Unity version is 2018.3.3.

elguero44 commented 5 years ago

What version should we use in the mean time?

@elguero44 did you add the -ObjC flag? I guess Apple missed with your app. It seems to happen even on the simplest project. It is something on the FBSDK for Unity. My previous game was also approved and released but I see that there are crashes on iPads. It also had the FBSDK

No I haven't added ObjC flag. Weird though that this would swap the behaviour...

sharonreytan commented 5 years ago

@elguero44 No, it solves the error on my iPhone. Try it. I can't test on an iPad but for that Apple rejects me. I think that for now I will release only for iPhones until the issue is fixed. I'll keep you updated if Apple will approve or reject it

NumaNumaNuma commented 5 years ago

No I haven't added ObjC flag. Weird though that this would swap the behaviour...

From what I've seen It happens on either wifi / 3G depending on which one is slower / faster where you are. And definitely add the objC flag, it fixed it for me a few months ago but now with all those recent posts I'm worried the problem is back with the new iOS / XCode. Waiting on more info from KylinChang 👍

elguero44 commented 5 years ago

I think it has something to do with the velocity of the internet connection? Because suddenly sometimes on data it works too...

oct-test commented 5 years ago

@KylinChang I have attached the crash report. Crash Report

happypepper commented 5 years ago

@sharonreytan By any chance, do you have a space after your app ID in the fb SDK edit settings panel? I found that I had one there by accident, after I removed it, the problem was fixed, even without the -ObjC flag. I will leave the ObjC flag there just in case.

sharonreytan commented 5 years ago

@happypepper Oh no if it is the issue I will feel so bad... I will check this asap. I don't think this is the case because I copied from the Facebook for Developers site by click, but everything is possible.. Did you check it on wifi, cellular and flight mode and everything was fine? Did it crash only on iOS? on which iOS version did it happen?

happypepper commented 5 years ago

I also copy pasted from FB developer site, but somehow the space was included. I tried wifi and cellular but not flight mode, they were both fine. With the space, it was breaking on cellular but fine on wifi. I've only been testing on 12.1.2

sharonreytan commented 5 years ago

@happypepper thank you so much for writing this, I will check if that's the case. Hopefully that's the issue

oct-test commented 5 years ago

@happypepper No extra spaces in the app id. Still crashes.

sharonreytan commented 5 years ago

hard to explain how it solved the issue for that day. Maybe the wifi was bad and it worked for my testers and I. Please ignore this, the error persists

@happypepper How can I send you some flowers???? You solved my issue!!!! Thanks!! @oct-test @elguero44 @pmusolino I had a space in my app name, I removed it. Boom. Everything works well even without the -ObjC flag.. I'm on the same wifi, same device, same os, same fbsdk with GameAnalytics on unity, same unity, same Xcode, same project... It was the only change I made and now it works like a charm every single launch...

ghost commented 5 years ago

I had the same issue with sdk 7.15.1 The problem seems to be in the FBUnityInterface.mm file at this line 114: [FBUnityUtility sendMessageToUnity:FBUnityMessageName_OnInitComplete userData:userData requestId:0];

if i comment this line out, everything works without crash

KylinChang commented 5 years ago

@happypepper How can I send you some flowers???? You solved my issue!!!! Thanks!! @oct-test @elguero44 @pmusolino I had a space in my app name, I removed it. Boom. Everything works well even without the -ObjC flag.. I'm on the same wifi, same device, same os, same fbsdk with GameAnalytics on unity, same unity, same Xcode, same project... It was the only change I made and now it works like a charm every single launch...

@sharonreytan Congratulations! Thank you @happypepper. I will investigate further on the reason and will add warning or fix the issue in the next release.

sharonreytan commented 5 years ago

@KylinChang thanks! Let's validate that everyone's errors with this issue got to solve it as well. I really hope so

happypepper commented 5 years ago

@sharonreytan Glad to be of help!

NumaNumaNuma commented 5 years ago

No extra spaces in the app id. Still crashes.

So @oct-test no extra space + objC flag still doesn't do it for you?

oct-test commented 5 years ago

@NumaNumaNuma @sharonreytan @KylinChang No extra space in the app id + objC flag = issue not resolved

I am able to see the in-game events in the Facebook Analytics dashboard. In my case, the build randomly crashes when the code tries to send an event.

sharonreytan commented 5 years ago

@oct-test try to change your app name to a single word, something like "production", remove the client token, copy the app id again and make sure that there are no spaces in the beginning and in the end. Make sure that your event messages have no spaces. Make sure that your iOS bundle ID is correct on the Facebook for Developers dashboard > settings > basic. In my case the crash was on load, now it runs well even without this -ObjC flag, but I don't send events to fb. Only initialize it. Does the game crash on load, or crashes in-game when you send an event?

oct-test commented 5 years ago

@sharonreytan

  1. Do I need to change the app name in Facebook Dashboard or in the Xcode project? Can you please help me understanding that how app name can possibly cause this issue?
  2. Where can I find the client token?
  3. I have checked and confirmed that there is no extra space in the app id.
  4. No spaces in the event messages.
  5. Yes, the iOS bundle id is correct on the Facebook dashboard.
  6. Yes, the game crashes on load and in-game too. But this crash is not continuous. It is happening randomly.
sharonreytan commented 5 years ago

@oct-test

  1. On unity > Facebook settings If you don't use unity then probably in the xcode. I assume that there is a bug in the FBSDK that it can't handle space in its input parameters. Maybe there is a regex that validates your string and it can't accept spaces... I don't know. It can be anything. As a developer you know that bugs can surprise you and be unexpected. If they were expected there wouldn't be any bugs ever! I don't know the cause but it will be solved in a future version hopefully, but for now try to do everything you can to find a workaround.
  2. On unity it's in the Facebook settings inspector
oct-test commented 5 years ago

Thank you for the explanation.

  1. Regarding the app name in the Facebook settings, that is an optional field just for our own purpose. I think Facebook is not using this information.
  2. I checked it and this field is already removed.

Were you able to reproduce the issue 100% times? If yes, what type of device (model and iOS version) and network connection you were testing the build?

sharonreytan commented 5 years ago

@oct-test

  1. Yep I agree, but an optional field can crash stuff as well. That's a bug. Try everything you can do to overcome it. It helped me then it might help you.
  2. Check every free text you can and remove spaces from it.

I didn't need the -ObjC flag anymore, ran the game on simulators and sent a test flight to friends. It works perfectly on their devices, with wifi or cellular or flight mode. On my iPhone 8 it runs smoothly as well. Beforehead the game crashed immediately on load without the -ObjC flag on wifi. Now everything runs as expected

sharonreytan commented 5 years ago

@KylinChang @oct-test My celebration was too early. The game has been rejected for the same reason -

On iPad running iOS 12.2 on wifi the game crashed

NumaNumaNuma commented 5 years ago

Better apple catching it than your users (that's what happened to me). If you can do without, temporarily, there's also the option of completely removing the sdk. I'll be holding out on my releases until this is fixed.

sharonreytan commented 5 years ago

For sure. Do you think I can release to iPhones only? I can't give up on the sdk. @NumaNumaNuma

NumaNumaNuma commented 5 years ago

Risky :)

elguero44 commented 5 years ago

Holding out on your release is not a solution. It seems that this problem exists for a long time now. At least 2 years. We went through all releases since 2017 and the problem is the same. There must be another solution that some devs accidentally do in order to not get the crashes.

NumaNumaNuma commented 5 years ago

For me as soon as I added the objC flag everything has been fine, for months. But it seems the problem is back, maybe because of the new iOS?

elguero44 commented 5 years ago

I actually realized that I have objC flag in my project all along. And still have the problem. I also checked back my older projects and I see that after doing an update to fb sdk 4.38 just recently my crash rate went down significantly. I'm doing a test right now with unity version 7.14.1 that has this version of fb sdk included. Will report back. We also moved the initialization to the start method (from the awake method).

Question: can we update manually in Xcode to the latest FB SDK, replacing the one that comes with Unity SDK? Anyone has tried that?

elguero44 commented 5 years ago

For me as soon as I added the objC flag everything has been fine, for months. But it seems the problem is back, maybe because of the new iOS?

I'm using ios 12.1.4 on the device I registered myself the problem. Unity version used is: 2018.2.9

sharonreytan commented 5 years ago

@elguero44 did anything you try solved this? I noticed that when the internet's downstream Mb/s is low it doesn't crash mostly

sharonreytan commented 5 years ago

I reopened the issue on Facebook: https://developers.facebook.com/support/bugs/2313553335596878/?disable_redirect=0

@oct-test @elguero44 @NumaNumaNuma @pmusolino and everyone else that experiences this, Please mark the "same here" flag

NumaNumaNuma commented 5 years ago

done 👍

NumaNumaNuma commented 5 years ago

Don't know if that has anything to do with it, but I noticed sometimes the LSApplicationQueriesSchemes values are not being added to the info.plist file. Maybe if they're missing and the sdk is trying to call them, it causes problems? I logged this as a separate issue but maybe they're related. "fbapi", "fb-messenger-api", "fbauth2", "fbshareextension"

oct-test commented 5 years ago

I reopened the issue on Facebook: https://developers.facebook.com/support/bugs/2313553335596878/?disable_redirect=0

@oct-test @elguero44 @NumaNumaNuma @pmusolino and everyone else that experiences this, Please mark the "same here" flag

Done.

oct-test commented 5 years ago

Don't know if that has anything to do with it, but I noticed sometimes the LSApplicationQueriesSchemes values are not being added to the info.plist file. Maybe if they're missing and the sdk is trying to call them, it causes problems? I logged this as a separate issue but maybe they're related. "fbapi", "fb-messenger-api", "fbauth2", "fbshareextension"

Can you please post the Facebook Bug Tracker link here?

NumaNumaNuma commented 5 years ago

https://github.com/facebook/facebook-sdk-for-unity/issues/229

I just logged it here on github

oct-test commented 5 years ago

Don't know if that has anything to do with it, but I noticed sometimes the LSApplicationQueriesSchemes values are not being added to the info.plist file. Maybe if they're missing and the sdk is trying to call them, it causes problems? I logged this as a separate issue but maybe they're related. "fbapi", "fb-messenger-api", "fbauth2", "fbshareextension"

In my Xcode project, all those schemes are present but the problem still persist. @NumaNumaNuma anything else I should look into?

@KylinChang we are looking for some help from you. Please let us know the progress made on the bug resolution by the Facebook team. Thank you.

oct-test commented 5 years ago

@KylinChang @NumaNumaNuma @sharonreytan Do you know how can we integrate the FB iOS SDK version 4.40 (latest FB iOS SDK) in this Unity version?

Current version of Unity FB SDK (v7.15.1) uses FB iOS SDK version 4.39.1.

The changelog here suggest that there are few bug fixes in the latest FB iOS SDK.

pmusolino commented 5 years ago

@oct-test also this version presents the issue.

KylinChang commented 5 years ago

Hey all, you can change SDK version by following steps: 1. change the version in scripts/build.properties 2. run ./scripts/setup.sh && ./scripts/build.sh. Open project UnitySDK and then export the package.

oct-test commented 5 years ago

@pmusolino Facebook iOS SDK 4.40 has this issue?

oct-test commented 5 years ago

Hello all,

On my end, the frequency of this crash issue in very low. I am thinking to release my game and try my luck.

I wanted to know if any other developer here got his/her game approved from Apple? If yes, are there any user complaints about the crash? What's the frequency of the crash on the users' end?

Thank you.

sharonreytan commented 5 years ago

@oct-test I wouldn't take the risk of releasing. On my wifi the crash happens every launch. You don't want users to give you bad reviews for these crashes, you put too much effort in it to be scored badly for crashes. People write bad reviews faster than they write good reviews. I decided to wait for a resolution before my release (a fix or a workaround, but stabilization is a must...)

NumaNumaNuma commented 5 years ago

I decided to release the app anyway, so far so good no crashes. just in case it helps, this is how I'm initializing the sdk (nothing special there but who knows maybe for those who have crashes on launch...):

private void Awake()
        {
            InitFBSDK();
        }

        private void InitFBSDK()
        {
            if (!FB.IsInitialized)
            {
                FB.Init(InitCallback);
            }
            else
            {
                // Already initialized, signal an app activation App Event
                FB.ActivateApp();
            }
        }

        public void InitCallback()
        {
            if (FB.IsInitialized)
            {
                // Signal an app activation App Event
                FB.ActivateApp();
            }
            else
            {
                Debug.Log("Failed to Initialize the Analytics SDK");
            }
        }

        private void OnApplicationPause(bool pauseStatus)
        {
            if (!pauseStatus)
            {
                if (FB.IsInitialized)
                {
                    FB.ActivateApp();
                }
                else
                {
                    FB.Init(InitCallback);
                }
            }
        }