OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
616 stars 213 forks source link

[Bug]: iOS removeSms and removeEmail methods crashes app #830

Closed inesga closed 8 months ago

inesga commented 8 months ago

What happened?

My app crashes when OneSignal.removeSms ou OneSignal.removeEmail is called in iOS. In Android works fine, but in iOS I get the Exception copied bellow.

I found out that the exception is in OSFlutterUser, on the second line of this code:

(void)removeSms:(FlutterMethodCall *)call withResult:(FlutterResult)result {
    NSString *smsNumber = call.arguments[@"smsNumber"];
    [OneSignal.User removeSms:smsNumber];
    result(nil);
}

The Exception I get is this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x6000003401e0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000180491128 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x000000018008412c objc_exception_throw + 56
    2   CoreFoundation                      0x00000001804a5f78 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
    3   CoreFoundation                      0x0000000180495278 ___forwarding___ + 1280
    4   CoreFoundation                      0x000000018049759c _CF_forwarding_prep_0 + 92
    5   Runner                              0x0000000104431884 -[OSFlutterUser removeSms:withResult:] + 116
    6   Runner                              0x000000010443102c -[OSFlutterUser handleMethodCall:result:] + 920
    7   Flutter                             0x000000010bc88400 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 116
    8   Flutter                             0x000000010b7636d4 _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageENSt3__110unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE + 224
    9   Flutter                             0x000000010b769210 _ZN7flutter15PlatformViewIOS21HandlePlatformMessageENSt3__110unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE + 40
    10  Flutter                             0x000000010bb5977c _ZNSt3__110__function6__funcIN3fml8internal14CopyableLambdaIZN7flutter5Shell29OnEngineHandlePlatformMessageENS_10unique_ptrINS5_15PlatformMessageENS_14default_deleteIS8_EEEEE4$_15EENS_9allocatorI  11  Flutter                             0x000000010ba61e5c _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 172
    12  Flutter                             0x000000010ba689c4 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 32
    13  CoreFoundation                      0x00000001803f2618 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
    14  CoreFoundation                      0x00000001803f22d4 __CFRunLoopDoTimer + 948
    15  CoreFoundation                      0x00000001803f1970 __CFRunLoopDoTimers + 284
    16  CoreFoundation                      0x00000001803ec0bc __CFRunLoopRun + 1796
    17  CoreFoundation                      0x00000001803eb5a4 CFRunLoopRunSpecific + 572
    18  GraphicsServices                    0x000000018e9fbae4 GSEventRunModal + 160
    19  UIKitCore                           0x00000001852f02e4 -[UIApplication _run] + 868
    20  UIKitCore                           0x00000001852f3f5c UIApplicationMain + 124
    21  Runner                              0x0000000104364b4c main + 64
    22  dyld                                0x0000000104689544 start_sim + 20
    23  ???                                 0x00000001048d20e0 0x0 + 4371325152
    24  ???                                 0xe516000000000000 0x0 + 16507381484173131776
)
libc++abi: terminating due to uncaught exception of type NSException

Steps to reproduce?

Flutter doctor -v

[✓] Flutter (Channel stable, 2.10.5, on macOS 14.2.1 23C71 darwin-arm,
    locale en-PT)
    • Flutter version 2.10.5 at /Users/b6user/Documents/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (1 year, 9 months ago), 2022-04-18
      09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0)
    • Android SDK at /Users/b6user/Library/Android/sdk
    • Platform android-34-ext8, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.15.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)

[✓] Connected device (3 available)
    • iPhone de B6 (mobile) • 00008110-000A6DDE1A8B801E            • ios
      • iOS 17.2.1 21C66
    • iPhone 15 (mobile)    • 6664DB7F-C940-4B08-AE50-407400224F2A • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • Chrome (web)          • chrome                               •
      web-javascript • Google Chrome 121.0.6167.85

[✓] HTTP Host Availability
    • All required HTTP hosts are available

One signal version: 5.0.4

What did you expect to happen?

No error exception.

OneSignal Flutter SDK version

5.0.4

Which platform(s) are affected?

Relevant log output

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x6000003401e0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000180491128 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x000000018008412c objc_exception_throw + 56
    2   CoreFoundation                      0x00000001804a5f78 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
    3   CoreFoundation                      0x0000000180495278 ___forwarding___ + 1280
    4   CoreFoundation                      0x000000018049759c _CF_forwarding_prep_0 + 92
    5   Runner                              0x0000000104431884 -[OSFlutterUser removeSms:withResult:] + 116
    6   Runner                              0x000000010443102c -[OSFlutterUser handleMethodCall:result:] + 920
    7   Flutter                             0x000000010bc88400 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 116
    8   Flutter                             0x000000010b7636d4 _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageENSt3__110unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE + 224
    9   Flutter                             0x000000010b769210 _ZN7flutter15PlatformViewIOS21HandlePlatformMessageENSt3__110unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE + 40
    10  Flutter                             0x000000010bb5977c _ZNSt3__110__function6__funcIN3fml8internal14CopyableLambdaIZN7flutter5Shell29OnEngineHandlePlatformMessageENS_10unique_ptrINS5_15PlatformMessageENS_14default_deleteIS8_EEEEE4$_15EENS_9allocatorI  11  Flutter                             0x000000010ba61e5c _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 172
    12  Flutter                             0x000000010ba689c4 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 32
    13  CoreFoundation                      0x00000001803f2618 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
    14  CoreFoundation                      0x00000001803f22d4 __CFRunLoopDoTimer + 948
    15  CoreFoundation                      0x00000001803f1970 __CFRunLoopDoTimers + 284
    16  CoreFoundation                      0x00000001803ec0bc __CFRunLoopRun + 1796
    17  CoreFoundation                      0x00000001803eb5a4 CFRunLoopRunSpecific + 572
    18  GraphicsServices                    0x000000018e9fbae4 GSEventRunModal + 160
    19  UIKitCore                           0x00000001852f02e4 -[UIApplication _run] + 868
    20  UIKitCore                           0x00000001852f3f5c UIApplicationMain + 124
    21  Runner                              0x0000000104364b4c main + 64
    22  dyld                                0x0000000104689544 start_sim + 20
    23  ???                                 0x00000001048d20e0 0x0 + 4371325152
    24  ???                                 0xe516000000000000 0x0 + 16507381484173131776
)
libc++abi: terminating due to uncaught exception of type NSException

Code of Conduct

inesga commented 8 months ago

Just checked that if I change the methods in OSFlutterUser.m of OneSignal_flutter pod to this, everything goes well:

(void)removeSms:(FlutterMethodCall *)call withResult:(FlutterResult)result {
    NSString *smsNumber = call.arguments;
    [OneSignal.User removeSms:smsNumber];
    result(nil);
}

(void)removeEmail:(FlutterMethodCall *)call withResult:(FlutterResult)result {
    NSString *email = call.arguments;
    [OneSignal.User removeEmail:email];
    result(nil);
}
emawby commented 8 months ago

@inesga Thank you for investigating we will get that fix in asap!

nan-li commented 8 months ago

It has been fixed in this PR and will be released.

nan-li commented 8 months ago

We have released the fix in Release 5.1.0, so I will close this issue.

Thanks again for submitting this issue!