nstack-io / nstack-ios-sdk

MIT License
5 stars 10 forks source link

Alert manager's showAlertBlock with url crashes after first open #83

Open mariusc opened 4 years ago

mariusc commented 4 years ago

See #76

Can be reproduced from that branch in the PR. Run the app, go to Alert Types, Tap on Open URL Alert and tap the Open URL button. It will open a webpage in safari. Go back and do that again. The app will crash

2020-11-10 11:38:44.646099+0100 NStackDemo[93925:1246807] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
Url Opened - https://www.hackingwithswift.com/
Url Opened - https://www.hackingwithswift.com/
2020-11-10 11:53:24.478593+0100 NStackDemo[93925:1246606] *** Assertion failure in -[BSServiceConnectionEndpointMonitor dealloc], BSServiceConnectionEndpointMonitor.m:58
2020-11-10 11:53:24.482040+0100 NStackDemo[93925:1246606] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'must call invalidate before dealloc'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff2043a126 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20177f78 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff20439f4f +[NSException raise:format:] + 0
    3   Foundation                          0x00007fff207881ca -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   BoardServices                       0x00007fff2576cb0e -[BSServiceConnectionEndpointMonitor dealloc] + 174
    5   libobjc.A.dylib                     0x00007fff2018f7f4 _ZN11objc_object17sidetable_releaseEbb + 174
    6   UIKitCore                           0x00007fff246894a0 -[UIApplication .cxx_destruct] + 60
    7   libobjc.A.dylib                     0x00007fff201771f0 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
    8   libobjc.A.dylib                     0x00007fff20189011 objc_destructInstance + 64
    9   libobjc.A.dylib                     0x00007fff2018ef6c -[NSObject dealloc] + 21
    10  UIKitCore                           0x00007fff24694429 -[UIResponder dealloc] + 145
    11  UIKit                               0x0000000110b7a507 -[UIResponderAccessibility dealloc] + 55
    12  UIKitCore                           0x00007fff2465a075 -[UIApplication dealloc] + 330
    13  UIKit                               0x0000000110b2c30b -[UIApplicationAccessibility dealloc] + 206
    14  libobjc.A.dylib                     0x00007fff2018f7f4 _ZN11objc_object17sidetable_releaseEbb + 174
    15  libsystem_blocks.dylib              0x00007fff2007f42f _Block_release + 128
    16  QuartzCore                          0x00007fff279c7394 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 100
    17  QuartzCore                          0x00007fff279930dc _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 12884
    18  QuartzCore                          0x00007fff279c6e13 _ZN2CA11Transaction6commitEv + 783
    19  QuartzCore                          0x00007fff279c7fcf _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 79
    20  CoreFoundation                      0x00007fff203a76b3 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    21  CoreFoundation                      0x00007fff203a1f3f __CFRunLoopDoObservers + 547
    22  CoreFoundation                      0x00007fff203a24e2 __CFRunLoopRun + 1113
    23  CoreFoundation                      0x00007fff203a1b9e CFRunLoopRunSpecific + 567
    24  GraphicsServices                    0x00007fff2b773db3 GSEventRunModal + 139
    25  UIKitCore                           0x00007fff24660af3 -[UIApplication _run] + 912
    26  UIKitCore                           0x00007fff24665a04 UIApplicationMain + 101
    27  libswiftUIKit.dylib                 0x00007fff539f37b2 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 98
    28  NStackDemo                          0x000000010e53a30a $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 122
    29  NStackDemo                          0x000000010e53a27e $s10NStackDemo11AppDelegateC5$mainyyFZ + 46
    30  NStackDemo                          0x000000010e53a359 main + 41
    31  libdyld.dylib                       0x00007fff20257415 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'must call invalidate before dealloc'
terminating with uncaught exception of type NSException
CoreSimulator 732.17 - Device: iPhone 11 (D2040475-F00F-4C3C-AF0C-A26F6CA547BB) - Runtime: iOS 14.0 (18A372) - DeviceType: iPhone 11

On a more or less related note: why would anyone use alerts like this? Why present alerts through NStack when you can do it much easily with the UIAlertController directly. Shouldn't AlertManager be private to NStack and only used by the SDK to show app update prompts or messages?

mariusc commented 4 years ago

We just had a discussion about this and, as suspected, the AlertManager shouldn't be used like this. Let's investigate why it's public and if it can be private and only take care of the alerts shown from the SDK (force update alerts, what's new in version, etc)