Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS App crashes after Resume from ScreenLock #202

Closed
malua opened this issue Aug 31, 2016 · 12 comments
Closed

iOS App crashes after Resume from ScreenLock #202

malua opened this issue Aug 31, 2016 · 12 comments

Comments

@malua
Copy link

malua commented Aug 31, 2016

When I lock the screen with the running app in foreground and then unlock again, the app crashes after 2 to 3 seconds. (this is not happening on android)
Its definitly branch, as it works if i remove the from the config.xml. do you have any idea what that could be?
What should happen if Branch.initSession() is called twice? Could that be the problem?

this is the log from safari: i doesn't say very much to me, also because you can see no code hints or anything else. but maybe you can extract some information from that.
crash log.txt

thanks for your support!

@malua malua closed this as completed Aug 31, 2016
@malua malua reopened this Sep 2, 2016
@malua
Copy link
Author

malua commented Sep 2, 2016

Sorry for reopening this, but the error didn't go away by updating to phonegap 6.3.0. i have figured out, that the error does not appear when Branch.setIdentity() is commented out. As soon as .setIdentity is called one time at startup, the app crashes when coming back from background or screen lock. Only happening on iOS.

@malua
Copy link
Author

malua commented Sep 5, 2016

Some more information: As I said, if .setIdentity is uncommented, it does not crash. Although if call Branch.setIdentity(2222222) (EDIT: from the debugging console), the identity is set correctly (as seen in dashboard), but if the app is reactivated from background then, it crashes.

@aaustin
Copy link
Contributor

aaustin commented Sep 5, 2016

Thanks for the extra info on this @malua. I'll have @renesansz take a look soon.

@renesansz
Copy link
Contributor

thanks for the info @malua, will look into this.

@renesansz
Copy link
Contributor

@malua , may I know what iOS version are you using? I've tested it on an actual device (iOS 9.3.5) and somehow the testbed app didn't crash.
I've tried doing the ff:

  1. Initialize Branch
  2. Set identity
  3. Lock phone/Minimize testbed app
  4. Unlock phone and open Branch/re-open testbed app
    But I wasn't able to reproduce the issue that you're making

Also, can you provide some sample codes?

Thanks

@malua
Copy link
Author

malua commented Sep 8, 2016

I have tested it on iOS 9.3.5 and 7.1.2. It's happening on both.
The testbed app is not a phonegap app, right? maybe it has to do with PhoneGap Build?

I am also not sure about the hooks working on PGB. could it be the PGB ignores a hook, and the app crashes because of this ? but it compiles fine, and all the features are working. As for the code samples. I just call Branch.initSession() in onDeviceReady and

function onResume(){
    setTimeout(function() {
          Branch.initSession().then(function (res) {
             console.log("initSession:");
             console.log(res);
        }).catch(function (err) {
            console.log("ERROR initSession:");
            console.error(err);
        });
    }, 0);
}

I added the timeout due to this : Cordova Docs Resume Event

and then I set the identity when loading a profile like this:

if(model && model.id){
        Branch.setIdentity(model.id).then(function (res) {
              // Success Callback
            console.log("setIdentity:");
            console.log(res);
        }).catch(function (err) {
              // Error Callback
            console.log("ERROR setIdentity:");
            console.error(err);
        });
}

If I uncomment the part about Branch.setIdentity() the app never crashes. and as i said if i call it manually from the debugging console in safari, the identity is set, but the app crashes after the next screenlock or if it was in the background.

EDIT: Could that be somehow related? https://stackoverflow.com/questions/39307116/application-with-branch-deep-linking-shows-uialertcontroller-warning-on-reopenin

@malua
Copy link
Author

malua commented Sep 8, 2016

Oh no, I am getting a really bad feeling:
phonegap/build#279 (comment)

Maybe it's not possible to use Branch with PhoneGap Build at the moment?

@aaustin
Copy link
Contributor

aaustin commented Sep 8, 2016

Hmm - thanks for linking to that PG error. I was unaware people were struggling with the entitlements that much. However, that's a very different error than the one you're describing and I'll address that in a separate issue I just created. I know this because at no point does the library read from the entitlements file. #207

Taking a look at your issue now.

@aaustin
Copy link
Contributor

aaustin commented Sep 8, 2016

I'm pretty sure this is related to an issue (BranchMetrics/ios-branch-deep-linking-attribution#424) on iOS that we just discovered, where it was possible for setIdentity to be executed before init was finished BranchMetrics/ios-branch-deep-linking-attribution#428. I bet this causes some crash on Cordova.

We'll get this merged in ASAP.

@malua
Copy link
Author

malua commented Sep 15, 2016

Is this merged already? I tried to add the plugin via git. and specified the branch update-ios-lib. unfortunately it is still crashing.

i moved our build process to local cli on osx. now i get better crash logs and now you can see its directly got to do with the setUserIdentity:

2016-09-15 13:07:53.238 Ticket Gretchen Wien[10667:455763] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7b15edc0
2016-09-15 13:07:53.517 Ticket Gretchen Wien[10667:455763] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7b15edc0'
*** First throw call stack:
(
    0   CoreFoundation                      0x02c4d494 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x026e0e02 objc_exception_throw + 50
    2   CoreFoundation                      0x02c57253 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x02b8c89d ___forwarding___ + 1037
    4   CoreFoundation                      0x02b8c46e _CF_forwarding_prep_0 + 14
    5   Ticket Gretchen Wien                0x002f4301 -[BNCPreferenceHelper setUserIdentity:] + 58
    6   Ticket Gretchen Wien                0x002f9e7f -[BranchOpenRequest processResponse:error:] + 538
    7   Ticket Gretchen Wien                0x002e9425 __30-[Branch processNextQueueItem]_block_invoke + 170
    8   Ticket Gretchen Wien                0x002f7ce4 __79-[BNCServerInterface genericHTTPRequest:retryNumber:log:callback:retryHandler:]_block_invoke.82 + 29
    9   libdispatch.dylib                   0x03c6a363 _dispatch_call_block_and_release + 15
    10  libdispatch.dylib                   0x03c8d9cd _dispatch_client_callout + 14
    11  libdispatch.dylib                   0x03c72f7c _dispatch_main_queue_callback_4CF + 910
    12  CoreFoundation                      0x02b971be __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
    13  CoreFoundation                      0x02b55434 __CFRunLoopRun + 2356
    14  CoreFoundation                      0x02b54846 CFRunLoopRunSpecific + 470
    15  CoreFoundation                      0x02b5465b CFRunLoopRunInMode + 123
    16  GraphicsServices                    0x04965664 GSEventRunModal + 192
    17  GraphicsServices                    0x049654a1 GSEventRun + 104
    18  UIKit                               0x0073aeb9 UIApplicationMain + 160
    19  Ticket Gretchen Wien                0x000d8d09 main + 89
    20  libdyld.dylib                       0x03cb7a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

@aaustin
Copy link
Contributor

aaustin commented Sep 15, 2016

Hey @malua - I've merged it in this morning as part of the 2.2.0 update. Please update and let me know if you still observe the issue. Thanks!

@malua
Copy link
Author

malua commented Sep 19, 2016

The update did not fix the issue, because the problem was a different one. I was calling .setIdentity with a integer, not a string. this works on android, but let's the app crash on ios due to this [__NSCFNumber isEqualToString:] in the branch ios sdk. maybe you can change that or make it more visible, that setIdentity can only be called with String. Thank you!

@malua malua closed this as completed Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants