Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5901] Local Notification with Sound will crash an app when eventListener triggered

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDuplicate
Resolution Date2018-09-20T09:42:26.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsios
ReporterMatthew Delmarter
AssigneeShak Hossain
Created2018-09-19T21:00:24.000+0000
Updated2018-09-20T09:42:28.000+0000

Description

This ticket is building on a recent bug fix around Local Notifications event handling. Please see TIMOB-26237 for details. Basically the previous fix works fine ... until you add the "sound" option to the localnotification. It does not matter if the sound string is pointing to a valid audio file or not, it has the same issue. The notification is clicked on by the user, and when the 'localnotificationaction' eventListener is triggered, the app will crash with the following error: {noformat} [ERROR] The application has crashed with an uncaught exception 'NSInvalidArgumentException'. [ERROR] Reason: [ERROR] -[UNNotificationSound boundBridge:withKrollObject:]: unrecognized selector sent to instance 0x600002a416e0 [ERROR] Stack trace: [ERROR] 0 CoreFoundation 0x000000010f89229b __exceptionPreprocess + 331 [ERROR] 1 libobjc.A.dylib 0x000000010e6b3735 objc_exception_throw + 48 [ERROR] 2 CoreFoundation 0x000000010f8b0fa4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 [ERROR] 3 CoreFoundation 0x000000010f896fb6 ___forwarding___ + 1446 [ERROR] 4 CoreFoundation 0x000000010f898e88 _CF_forwarding_prep_0 + 120 [ERROR] 5 Playpen 0x00000001081ad552 -[KrollBridge registerProxy:krollObject:] + 194 [ERROR] 6 Playpen 0x00000001081ad649 -[KrollBridge registerProxy:] + 233 [ERROR] 7 Playpen 0x000000010841db99 TiBindingTiValueFromProxy + 281 [ERROR] 8 Playpen 0x000000010841da39 TiBindingTiValueFromNSObject + 3865 [ERROR] 9 Playpen 0x000000010841ca26 TiBindingTiValueFromNSDictionary + 454 [ERROR] 10 Playpen 0x000000010841b4f4 TiBindingEventProcess + 276 [ERROR] 11 Playpen 0x000000010841bae8 -[TiBindingCallbackInvoke invoke:] + 56 [ERROR] 12 Playpen 0x00000001081b3383 -[KrollContext invoke:] + 163 [ERROR] 13 Playpen 0x00000001081b345b __24-[KrollContext enqueue:]_block_invoke + 43 [ERROR] 14 Playpen 0x00000001082c420e TiThreadPerformOnMainThread + 78 [ERROR] 15 Playpen 0x00000001081b3428 -[KrollContext enqueue:] + 136 [ERROR] 16 Playpen 0x000000010841bb52 TiBindingRunLoopEnqueue + 98 [ERROR] 17 Playpen 0x000000010841b002 TiBindingEventFire + 338 [ERROR] 18 Playpen 0x0000000108282d01 -[TiProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 209 [ERROR] 19 Playpen 0x000000010828290d -[TiProxy fireEvent:withObject:] + 141 [ERROR] 20 Playpen 0x00000001083cc6e3 -[TiAppiOSProxy didReceiveLocalNotificationAction:] + 83 [ERROR] 21 CoreFoundation 0x000000010f7cffbc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 [ERROR] 22 CoreFoundation 0x000000010f7cf43f _CFXRegistrationPost + 447 [ERROR] 23 CoreFoundation 0x000000010f7cf181 ___CFXNotificationPost_block_invoke + 225 [ERROR] 24 CoreFoundation 0x000000010f8b7b42 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826 [ERROR] 25 CoreFoundation 0x000000010f7ceaa4 _CFXNotificationPost + 964 [ERROR] 26 Foundation 0x000000010af99788 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66 [ERROR] 27 Playpen 0x0000000108384dd5 __70-[TiApp tryToPostNotification:withNotificationName:completionHandler:]_block_invoke + 101 [ERROR] 28 Playpen 0x0000000108384d12 -[TiApp tryToPostNotification:withNotificationName:completionHandler:] + 162 [ERROR] 29 Playpen 0x0000000108383ef0 -[TiApp userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 704 [ERROR] 30 UIKitCore 0x000000011ac0af4e -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 5326 [ERROR] 31 UIKitCore 0x000000011b495964 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 2412 [ERROR] 32 UIKitCore 0x000000011b452b31 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 795 [ERROR] 33 UIKitCore 0x000000011b4527db -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 435 [ERROR] 34 UIKitCore 0x000000011b49792c __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 584 [ERROR] 35 UIKitCore 0x000000011b498256 _performActionsWithDelayForTransitionContext + 100 [ERROR] 36 UIKitCore 0x000000011b49768b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 221 [ERROR] 37 UIKitCore 0x000000011b490aa1 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392 [ERROR] 38 UIKitCore 0x000000011ac22d42 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 502 [ERROR] 39 FrontBoardServices 0x0000000119f9cadb __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.359 + 213 [ERROR] 40 libdispatch.dylib 0x0000000110da5587 _dispatch_client_callout + 8 [ERROR] 41 libdispatch.dylib 0x0000000110da8647 _dispatch_block_invoke_direct + 312 [ERROR] 42 FrontBoardServices 0x0000000119fdb3c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30 [ERROR] 43 FrontBoardServices 0x0000000119fdb080 -[FBSSerialQueue _performNext] + 457 [ERROR] 44 FrontBoardServices 0x0000000119fdb660 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 [ERROR] 45 CoreFoundation 0x000000010f7f5b31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 [ERROR] 46 CoreFoundation 0x000000010f7f53a3 __CFRunLoopDoSources0 + 243 [ERROR] 47 CoreFoundation 0x000000010f7efa4f __CFRunLoopRun + 1263 [ERROR] 48 CoreFoundation 0x000000010f7ef221 CFRunLoopRunSpecific + 625 [ERROR] 49 GraphicsServices 0x00000001126b61dd GSEventRunModal + 62 [ERROR] 50 UIKitCore 0x000000011abf4115 UIApplicationMain + 140 [ERROR] 51 Playpen 0x00000001081987a6 main + 102 [ERROR] 52 libdyld.dylib 0x0000000110e15551 start + 1 {noformat} Please use the sample code below. This is Hans code from the previous ticket TIMOB-26237, but I added the sound parameter to the scheduleLocalNotification.
// An action that opens the app (foreground action)
var acceptAction = Ti.App.iOS.createUserNotificationAction({
    identifier: 'ACCEPT_IDENTIFIER',
    title: 'Accept',
    activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
    destructive: false,
    authenticationRequired: true
  });

  // An action that does not open the app (background action)
  var rejectAction = Ti.App.iOS.createUserNotificationAction({
    identifier: 'REJECT_IDENTIFIER',
    title: 'Reject',
    activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
    destructive: true,
    authenticationRequired: false
  });

  // An action that does not open the app (background action), but lets the developer
  // type in a text (iOS 9+)
  var respondAction = Ti.App.iOS.createUserNotificationAction({
    identifier: 'RESPOND_IDENTIFIER',
    title: 'Respond',
    activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
    behavior: Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_TEXTINPUT, // or: Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_DEFAULT,
    authenticationRequired: false
  });

  // Create an example notification category
  var downloadContent = Ti.App.iOS.createUserNotificationCategory({
    identifier: 'DOWNLOAD_CONTENT',
    actionsForDefaultContext: [acceptAction, rejectAction, respondAction]
  });

  // Register for user notifications and categories
  Ti.App.iOS.registerUserNotificationSettings({
    types: [
      Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT
    ],
    categories: [downloadContent]
  });

  // Monitor notifications received while app is in the background
  Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
    alert('event: localnotificationaction');
  });

  Ti.App.iOS.addEventListener('usernotificationsettings', function(e) {
    alert('event: usernotificationsettings');
  })

  // Monitor notifications received while app is in the foreground
  Ti.App.iOS.addEventListener('notification', function(e) {
    alert('event: notification');
  });

  // App UI
  var win = Ti.UI.createWindow({
    backgroundColor: 'white'
  });
  var button = Ti.UI.createButton({
    title: 'Trigger Notification'
  });

  button.addEventListener('click', function(e) {
    // Send a notification in 3 seconds
    var note = Ti.App.iOS.scheduleLocalNotification({
      date: new Date(new Date().getTime() + 3000),
      alertTitle: 'My download',
      alertSubtitle: 'Check it out!',
      alertBody: 'New content available! Download now?',
      sound: '/alert.wav', << this causes the crash
      badge: 1,
      userInfo: {
        'url': 'http://www.download.com/resource/asset.json',
        id: '1'
      },
      category: 'DOWNLOAD_CONTENT'
    });
  });

  win.add(button);
  win.open();

Comments

  1. Hans Knöchel 2018-09-20

    Thanks for the report [~mdelmarter]! It's actually handled via TIMOB-26399 and [this commit](https://github.com/appcelerator/titanium_mobile/pull/10330/commits/1071673267b049622696f711688062a4025c5756) already, landing in 7.4.1 asap!

JSON Source