Emulator crashes app local notification

I’m using the local notification plugin (https://github.com/katzer/cordova-plugin-local-notifications/) with ng-cordova:

This is my controller:

.controller('DashCtrl', function($scope, $state, $cordovaLocalNotification) {

	$scope.addNotification = function () {
			$cordovaLocalNotification.add({
  			id: 'some_notification_id'
  				// parameter documentation:
  			// https://github.com/katzer/cordova-plugin-local-notifications#further-informations-1
			}).then(function () {
  					console.log('callback for adding background notification');
			});
	};
	
	
	
	$scope.checkIfIsTriggered = function () {
		
		$cordovaLocalNotification.isTriggered('some_notification_id').then(function (isTriggered) {
  		
  			alert('isTriggered');
		
		});
	};



})

I have a button on the default view which is loaded when the app starts with a ng-click, like so:

<button ng-click="addNotification();" class="button button-stable">
button-stable</button>

But when I run the app in the emulator and tap the button, the app crashes with the followiing error message:

: *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFString stringValue]: unrecognized selector sent to instance 0x7a840850’
*** First throw call stack:
(
0 CoreFoundation 0x002cc1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x023848e5 objc_exception_throw + 44
2 CoreFoundation 0x00369243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x002bc50b forwarding + 1019
4 CoreFoundation 0x002bc0ee _CF_forwarding_prep_0 + 14
5 new 0x0011f917 -[APPLocalNotification notificationWithId:] + 503
6 new 0x0011f6a6 -[APPLocalNotification isNotificationScheduledWithId:] + 86
7 new 0x0011bccf __28-[APPLocalNotification add:]_block_invoke + 207
8 libdispatch.dylib 0x0293d7b8 _dispatch_call_block_and_release + 15
9 libdispatch.dylib 0x029524d0 _dispatch_client_callout + 14
10 libdispatch.dylib 0x02940eb7 _dispatch_root_queue_drain + 291
11 libdispatch.dylib 0x02941127 _dispatch_worker_thread2 + 39
12 libsystem_pthread.dylib 0x02c89dab _pthread_wqthread + 336
13 libsystem_pthread.dylib 0x02c8dcce start_wqthread + 30
)
Oct 19 11:54:21 xxxx-MacBook-Air.local backboardd[27466] : Application ‘UIKitApplication:com.ionicframework.new903016[0xde04]’ exited abnormally with signal 6: Abort trap: 6"

Thera are a couple of questions about ng-cordova and the local notification plugin in the forum. Has anyone got it to work following the ng-cordova docs, or is ther another approach I should be trying.

Thank’s!

The solution is here:

Thank you for this, I will try your solution in a moment. Just to be sure, are you using
a) the plugin with ng-cordova and following th ng-cordova docs for implementation http://ngcordova.com/docs/#LocalNotification
b) using iphone ios8

I’m not using ngCordova, since it doesn’t support iOS 8, which requires to ask the user for permissions for local notifications.

 $ionicPlatform.ready(function() { // wrap 
      window.plugin.notification.local.promptForPermission(); // prompts the user on iOS 8
           window.plugin.notification.local.hasPermission(function(granted) {
          // add notification code...

Ok, I did not know this. So you just follow the official doc of the plugin then? I will test this and be sure to let you know. Thank’s for helping out!

Yes, the doc on the 0.7 branch:

Hi,

I’ve changed the APPLocalNotification.m file to:

for (UILocalNotification* notification in notifications)
{
    
	NSString* notId = NULL;
		
		if ([[notification.userInfo objectForKey:@"id"] isKindOfClass:[NSString class]] ) {
			notId = [notification.userInfo objectForKey:@"id"];
			
			} else {
			
			notId = [[notification.userInfo objectForKey:@"id"] stringValue];
		
		}


    

    if ([notId isEqualToString:id]) {
        return notification;
    }
}

My controller:

	 $ionicPlatform.ready(function() { // wrap 
	 
	 		
  			
  			window.plugin.notification.local.promptForPermission(); // prompts the user on iOS 8
       				
       				window.plugin.notification.local.hasPermission(function(granted) {
       				
       				
       				var now  = new Date().getTime();
					var _60_seconds_from_now = new Date(now + 10*1000);

			window.plugin.notification.local.add({
					id:      '1',
					title:   'Reminder',
					message: 'Dont forget to buy some flowers.',
					repeat:  'minutely',
					date:  _60_seconds_from_now
			});


			});
		
	});	

When I run it on iphone 6 I get the following message:

2014-10-20 21:28:16.588 myNote[74597:511478] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]: unrecognized selector sent to instance 0x7fbde2d51d70' 

The thing is that I get this errror message in the output window, and the simulator “disappears” as the front view on my screen, but it doesn’t really go away, so I can tab the simulator to the front and the notifications are actually running.

I have not tried this on a actual device.

Do you see the same on iphone 6 ios 8?

Ok, so now I got this to work. My mistake was that I didn’t check the plugin file in the xcode tree. I edited it in my text editor, but for some reason the code in xcode did not get updated when I rebuilt the app. Anyway, thank you a lot for providing guidance!

Hi,

Reviving this thread. Any solution to this? Thanks!