katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

Is this plug-in still working in iOS 9 ? #694

Closed richardshergold closed 8 years ago

richardshergold commented 9 years ago

I'm trying to get LocalNotifications working in my Ionic project but whatever I do (and I've tried all sorts of methods!) my app crashes when I fire the notification. It always crashes on the same line in the fireDate method of AppLocationNotifications.m

double timestamp = [[dict objectForKey:@"at"]

Anyone else experiencing the same thing?

FlossyWeb commented 9 years ago

+1 Same here the plugins results in an app crash on iOS 9 and 9.01

jfaigan commented 9 years ago

+1 I too am having issues with iOS 9. While debugging I see that it is dropping into the code to setup the dictionary many times. At some point the dictionary is nil and then the errors start happening.

/**

The strange thing is that I have noticed a difference between letting the app run vs stepping through the plugin code...if I step through the code then I do not always get an error at the same place...but the error always has to do with the options dictionary not being initialized.

Hopefully this can be fixed.

Thanks.

FlossyWeb commented 9 years ago

@jfaigan @richardshergold in phonegap build someone just uploaded a new plugin that fixes this: <gap:plugin name="de.appplant.cordova.plugin.local-notification-ios9-fix" version="0.8.2" /> see the plugin's page : here on pgb website I've tried and works for me ;-)

jfaigan commented 9 years ago

Hi FlossyWeb,

Thanks! I will check it out and post back if it works for me too.

Regards!

Edit: Confirmed! Is working for me too. No longer crashing on null dictionary!

richardshergold commented 9 years ago

Thanks @FlossyWeb and @jfaigan its a relief to know it wasn't something I was doing wrong :-)

richardshergold commented 9 years ago

Hi

@FlossyWeb @jfaigan I'm a little unsure how to install that latest version. This is in an Ionic project.

Do I install the plug-in like I normally would i.e:

cordova plugin add de.appplant.cordova.plugin.local-notification

and then add the "<gap:plugin name= etc etc " line to my config.xml ?

I tried that and I still get the old error.

Presumably there's a way I can add that plug-in version directly? I tried these two options but neither worked:

cordova plugin add de.appplant.cordova.plugin.local-notification-ios9-fix cordova plugin add de.appplant.cordova.plugin.local-notification-ios9-fix version="0.8.2"

I'm new to all this (Ionic, Phonegap etc) so would appreciate any pointers you can give me!

many thanks

Richard

jfaigan commented 9 years ago

@richardshergold Here are the commands I used to get this plugin installed:

cordova plugin remove de.appplant.cordova.plugin.local-notification cordova plugin add https://github.com/willyboy/cordova-plugin-local-notifications.git ionic build ios

Hopefully this will work for you.

Good luck.

Joel.

mr-sparks commented 9 years ago

@jfaigan @FlossyWeb When i install the Plugin (https://github.com/willyboy/cordova-plugin-local-notifications.git) I can't build my app anymore....I keep getting the following..

Any ideas on that? Every help greatly appreciated !!!


UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/NotificationCompatHoneycomb; at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122) at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at com.android.dx.command.dexer.Main.processClass(Main.java:732) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) at com.android.dx.command.dexer.Main.access$300(Main.java:83) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:632) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106)

UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/NotificationCompat$Builder; at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122) at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at com.android.dx.command.dexer.Main.processClass(Main.java:732) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) at com.android.dx.command.dexer.Main.access$300(Main.java:83) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:632) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106) 2 errors; aborting :dexArmv7Debug FAILED

FAILURE: Build failed with an exception.

BUILD FAILED

jfaigan commented 9 years ago

@mr-sparks wow...no clue. did you try removing the plugins "cordova plugins remove..." and then adding them back in?

mr-sparks commented 9 years ago

@jfaigan thanks for the fast answer! yeah i actually have no idea what happend. I had it running once with the regular "katzer" version when it started crashing in iOS.. I tried katzers version now, then the willyboys and there was another one i think... won't let me build :(

jfaigan commented 9 years ago

@mr-sparks found this on SO: http://stackoverflow.com/questions/9164005/unexpected-top-level-exception-java-lang-illegalargumentexception-already-adde

The ADT will throw an exception like this if your Eclipse classpath contains more than one class of the same name/package. In this case it is encountering more than one instance of the AvailabilityRequest class in your Maven dependencies.

You can resolve this by finding which classpath dependencies contain the same class files in them (hitting Ctrl-Alt-T and typing in AvailabilityRequest will do this).

If you run "cordova plugin list" do you see anything weird?

Tawpie commented 9 years ago

@jfaigan… the “other” one that works for me (I can build both Android and iOS for 9.0.2—although I’m not certain it actually does anything on 9.0.2 but at least it builds) is

cordova plugins add https://github.com/excendia/cordova-plugin-local-notifications.git

It’s a fork. It doesn’t look like Katzer is working on this plugin much at all—perhaps a few euros might help restart progress.

On Oct 2, 2015, at 9:54 AM, jfaigan notifications@github.com wrote:

@mr-sparks found this on SO: http://stackoverflow.com/questions/9164005/unexpected-top-level-exception-java-lang-illegalargumentexception-already-adde

The ADT will throw an exception like this if your Eclipse classpath contains more than one class of the same name/package. In this case it is encountering more than one instance of the AvailabilityRequest class in your Maven dependencies.

You can resolve this by finding which classpath dependencies contain the same class files in them (hitting Ctrl-Alt-T and typing in AvailabilityRequest will do this).

If you run "cordova plugin list" do you see anything weird?

— Reply to this email directly or view it on GitHub.

mr-sparks commented 9 years ago

@jfaigan Thanks for the assistance! This is my first time working with this whole thing, so i dont exactly know how to solve that thing with the dependencies. Do i have to do this in Android Studio? If yes in which file exactly?

When i type cordova plugin list i'll get this (which looks fine to me so far?!):

android.support.v4 21.0.1 "Android Support v4" cordova-plugin-crosswalk-webview 1.3.1 "Crosswalk WebView Engine" cordova-plugin-device 1.0.1 "Device" cordova-plugin-geolocation 1.0.1 "Geolocation" cordova-plugin-network-information 1.0.1 "Network Information" cordova-plugin-touchid 0.3.0 "Touch ID" cordova-plugin-websocket 0.11.0 "WebSocket for Android" cordova-plugin-whitelist 1.1.0 "Whitelist" de.appplant.cordova.common.registerusernotificationsettings 1.0.1 "RegisterUserNotificationSettings" de.appplant.cordova.plugin.local-notification-ios9-fix 0.8.2 "LocalNotification" org.apache.cordova.splashscreen 1.0.0 "Splashscreen"

jfaigan commented 9 years ago

@Tawpie thanks for the info! the willyboy fork seems to be working for me - although I still have an issue when the app is in the background...still working on that.

jfaigan commented 9 years ago

@mr-sparks unfortunately I do not have that much more experience. I am using ionic and angular with Visual Studio. I am using cordova to wrap that up for running on iOS and Android.

The only thing that I could recommend at this point is starting a small project from scratch to see if you can get it working. If that succeeds, start adding your stuff back in. Not an ideal solution but it may help.

Good luck!

mr-sparks commented 9 years ago

@Tawpie @jfaigan The "other" version worked for me now. I can build again with this Version:

https://github.com/excendia/cordova-plugin-local-notifications.git

But the problem in my App is still there. As soon as i want to set a reminder, Xcode throws an EXC_BAD_ACCESS (code=1, address = 0x10):

/**

jfaigan commented 9 years ago

@mr-sparks that exc_bad_access is the error that I was getting with the Katzer version. The willyboy fork solved that exact problem for me.

mr-sparks commented 9 years ago

@jfaigan damn... why i can't i build it with willyboy's version, i need to get this app done :-)

jfaigan commented 9 years ago

@mr-sparks I did notice one thing in your plugin list. you are using an older version of "android support". try removing the one you are using and adding this one instead: cordova-plugin-android-support-v4 21.0.1 "Android Support v4"

mr-sparks commented 9 years ago

@jfaigan Thanks! I tried that, removed the old one and installed the one you suggested. Now when I'm trying to build i'm getting:

Cannot find plugin.xml for plugin 'android.support.v4'. Please try adding it again.

What did i do wrong?

jfaigan commented 9 years ago

@mr-sparks did you remove it via "cordova plugin remove"? it seems that you still have some code somewhere that is trying to use the old name. maybe some config files did not get updated properly

mr-sparks commented 9 years ago

@jfaigan yep, removed it this way.. any idea where i should look? When i try to delete the plugin you suggested im getting:

Uninstalling cordova-plugin-android-support-v4 from android Cannot find plugin.xml for plugin 'android.support.v4'. Please try adding it again.

jfaigan commented 9 years ago

@mr-sparks this is the contents of my plugin.xml for cordova-plugin-android-support-v4

It is located in the plugins folder. If the file does not exist in your plugin folder try to create it manually.

I am not sure what is happening. Did you try a new clean project to see if it creates the plugins correctly?

update: i am unable to paste the contents of the xml. i will add it as an attachment.

plugin xml

mr-sparks commented 9 years ago

@jfaigan I'll try to set everything up from a clean project now.. maybe that solves all the other errors too

mr-sparks commented 9 years ago

@jfaigan

set up a clean project, now everythings works fine again. When i use willys version i can place a timer once without a problem, when i try to set another one after the first one the app crashes again, xcode says (Markt Errors with // ):

/**

{ self = [super init]; // Convenience initializer should not invoke an initializer on 'super' [self setUserInfo:dict]; // Thread 17: signal SIGABRT [self __init]; return self; }

jfaigan commented 9 years ago

@mr-sparks I have not seen this issue yet but I have not played too much with it yet. I have seen those "convenience" messages but they are just build warnings. The Thread 17: signal SIGABRT looks like the problem...but I have not seen that one yet.

Out of curiosity, are you changing the notification id so a new one is created or are you trying to update an existing notification?

Glad to hear you are moving forward!

mr-sparks commented 9 years ago

@jfaigan this is how i create my timer:

timerID is always set to a new number before setting the timer

var sound = device.platform == 'Android' ? 'file://sound.mp3' : 'file://beep.caf';

cordova.plugins.notification.local.schedule({ id: timerID, text: "text to display", at: date, sound: sound });

mr-sparks commented 9 years ago

@jfaigan

Funny Fact:

When i rm the plugin https://github.com/willyboy/cordova-plugin-local-notifications.git and then reinstall it, i can't build anymore and get the same long "UNEXCPECTED TOP-LEVEL EXCEPTION" errors:

Error Code: 2 Output:

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/NotificationCompatHoneycomb; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106)

jfaigan commented 9 years ago

@mr-sparks your code looks like it should work. here is mine:

$cordovaLocalNotification.schedule({ id: $scope.info.id, title: 'First Test', text: 'message from ' + username + ': '+ message, badge: $scope.info.id, data: { customProperty: 'custom value' } }).then(function (result) { $log.log("in schedule: " + result); });

I am pretty sure I tried by sending multiple notifications and it was working. I will try it out again to be sure.

That "top-level" exception is weird...I have no idea what it is doing. Is your version of cordova up to date?

mr-sparks commented 9 years ago

@jfaigan yep, got everything updated to the latest version right now

mr-sparks commented 9 years ago

@jfaigan let me know when you had the chance to test if you can set multiple reminders after another without crashing the app

Tawpie commented 9 years ago

@mr-sparks

I’ve been able to keep things working (barely) by using a local copy of the katzer plugin. You need to go to his github page and clone the repo to your local machine, and then add the plugin using the “local” technique.

I put the cloned repro one folder below the root of my project, so to load the plugin I run cordova plugins add ../cordova-plugin-local-notifications/

A couple of other things. When you get that wacky “please add the plugin” when you’re trying to remove a plugin, it’s looking for a dependency that doesn’t exist so it can’t remove it. At that stage what I do is a multi-step recovery:

delete the platforms. All of them Delete the plugins with this: for i in cordova plugin ls | grep '^[^ ]*' -o; do cordova plugin rm $i; done ^^ will peel off the layers of dependencies so I do that several times until it has nothing left to remove. add the platforms add the plugins I’m getting from the internet add the local clone of the katzer plugin

Keep in mind that there are collisions galore in the plugins, and if you use the phonegap-build/PushPlugin you MUST use v2.4.0 or you get back into a mess during predexing.

On Oct 2, 2015, at 12:31 PM, mr-sparks notifications@github.com wrote:

@jfaigan let me know when you had the chance to test if you can set multiple reminders after another without crashing the app

— Reply to this email directly or view it on GitHub.

mr-sparks commented 9 years ago

@jfaigan thanks for the update! Unfortunately a local clone didn't fix it here... I can't build with that version either..

Following error:

/Users/harddrive/Projects/appTest/platforms/ios/appTest/Plugins/de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m:44:19: warning: convenience initializer should not invoke an initializer on 'super' [-Wobjc-designated-initializers] self = [super init]; ^ /Users/harddrive/Projects/appTest/platforms/ios/appTest/Plugins/de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m:42:1: warning: convenience initializer missing a 'self' call to another initializer [-Wobjc-designated-initializers]

Ld build/emulator/appTest.app/appTest normal i386 cd /Users/harddrive/Projects/appTest/platforms/ios export IPHONEOS_DEPLOYMENT_TARGET=6.0 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk -L/Users/harddrive/Projects/appTest/platforms/ios/build/emulator -F/Users/harddrive/Projects/appTest/platforms/ios/build/emulator -filelist /Users/harddrive/Projects/appTest/platforms/ios/build/appTest.build/Debug-iphonesimulator/appTest.build/Objects-normal/i386/appTest.LinkFileList -mios-simulator-version-min=6.0 -Xlinker -objc_abi_version -Xlinker 2 -weak_framework CoreFoundation -weak_framework UIKit -weak_framework AVFoundation -weak_framework CoreMedia -weak-lSystem -ObjC -fobjc-arc -fobjc-link-runtime -framework AssetsLibrary /Users/harddrive/Projects/appTest/platforms/ios/build/emulator/libCordova.a -framework CoreGraphics -framework MobileCoreServices -framework CoreLocation -weak_framework SystemConfiguration -framework LocalAuthentication -framework Security -Xlinker -dependency_info -Xlinker /Users/harddrive/Projects/appTest/platforms/ios/build/appTest.build/Debug-iphonesimulator/appTest.build/Objects-normal/i386/appTest_dependency_info.dat -o /Users/harddrive/Projects/appTest/platforms/ios/build/emulator/appTest.app/appTest duplicate symbol _UIApplicationRegisterUserNotificationSettings in: /Users/harddrive/Projects/appTest/platforms/ios/build/appTest.build/Debug-iphonesimulator/appTest.build/Objects-normal/i386/AppDelegate.o /Users/harddrive/Projects/appTest/platforms/ios/build/appTest.build/Debug-iphonesimulator/appTest.build/Objects-normal/i386/AppDelegate+APPRegisterUserNotificationSettings.o ld: 1 duplicate symbol for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

cantecim commented 9 years ago

@mr-sparks just remove the platforms/android/libs/android-support-v4.jar file and then re-build your app

FlossyWeb commented 9 years ago

Hi there, Can someone just remove the platforms/android/libs/android-support-v4.jar IN THE PHONEGAP BUILD PLUGIN please ? I do think it may be the solution for all PGB users that would like to build with cli-5.1.1 or 5.2.0 related to This issue Thank you guys...

jfaigan commented 9 years ago

@mr-sparks sorry for the delay...weekend and working on a different project...

I am able to send multiple local notifications, one at a time...I have not tried multiple in batches. My application schedules the local notifications to fire immediately...they are not queued up for a future date.

ghost commented 9 years ago

Hey guys.

I have this plugin installed on my ios app but im not using it. Do i have a risk of crashing the app just by having this on the app?

jfaigan commented 9 years ago

@unskaa doubt it. It was crashing for me when trying to schedule a local notification. If you are not using it I do not see why it would cause any issues.

ghost commented 9 years ago

Awesome. Thanks for the lightning fast reply! 7.10.2015 0.42 "jfaigan" notifications@github.com kirjoitti:

@unskaa https://github.com/unskaa doubt it. It was crashing for me when trying to schedule a local notification. If you are not using it I do not see why it would cause any issues.

— Reply to this email directly or view it on GitHub https://github.com/katzer/cordova-plugin-local-notifications/issues/694#issuecomment-146009980 .

mr-sparks commented 9 years ago

@jfaigan @cantecim thanks for the info!

Im not sending in batches either. I get the crash when i set one timer in the future.

I talked to Katzer by the way and asked if there's any chance that he'll fix the whole thing.. I'll hear again from im in a few days. Maybe we guys can pool expenses for this so everyone will profit of a working plugin, for a couple bucks each, again !?

jfaigan commented 9 years ago

@mr-sparks I am using the willyboy fork and I was able to schedule a notification for 10 seconds in the future and it worked. were you successful in getting the willyboy fork working in your project?

mr-sparks commented 9 years ago

@jfaigan only one works. My notifications are always in the future (reminds you when a ticket you bought is due). But as soon as i buy another ticket and set a notification for this one, the app crashes.

katzer commented 9 years ago

You will need version 0.8.2. Lower version do not support iOS 9. I will release that update soon.

richsage commented 9 years ago

@katzer do you have a rough timeline/estimate of release date?

owenhoskins commented 9 years ago

+1

Tawpie commented 9 years ago

Referencing the OP's error at the top of the thread (crash due to dict) I've had to resort to a different combination of plugins depending on the platform because what works for Android doesn't work for iOS (9.0.x). A key workflow note is when I change platforms I have resorted to removing all platforms, removing all plugins, and then reinstalling plugins and finally reinstalling platforms. Anyway, the combos that work for me (I have a script that does all that typing):

ANDROID: this combo works for android but can crash on ios due to something related to dict properties cordova plugins add https://github.com/phonegap-build/PushPlugin.git cordova plugins add https://github.com/excendia/cordova-plugin-local-notifications.git

iOS: this combo works for iOS but fails to build on Android during preDexing cordova plugins add https://github.com/phonegap-build/PushPlugin.git#2.4.0 cordova plugins add https://github.com/katzer/cordova-plugin-local-notifications.git

* yet another plug to send Katzer some euros. we can't ask for too much support without providing support in return *

JLNNN commented 8 years ago

I used the plugin on https://build.phonegap.com/plugins/4859

ionic plugin remove de.appplant.cordova.plugin.local-notification ionic plugin add https://github.com/willyboy/cordova-plugin-local-notifications.git

Running my app on iOS 9.0.2

neil-rowe commented 8 years ago

I am up and running smoothly with 8.2-dev on iOS 9 and also seems to run fine on iOS 8. both real world devices. i dont have a iOS 7 real world device to test on though. It took some tweaking to my code though. i realized that the new dev version does not like it when you run any functions (get, scheduled, present, ect.) with an id of 0. so i changed the notification that was scheduling using that id in my previous app version to a different number and converted all my ids to use integers. perviously it did not run in some functions unless i used a string as the definitions look for strings. anyway it seems to be up and running again without any crashes and ready to update for iOS 9 support. I just want to thank you Katzer for your continued work on this!

richsage commented 8 years ago

8.2-dev works here as well with iOS9. I had the same issue as @neil-rowe with regards to older notifications (we had used a millisecond timestamp, which was too big a number for the iOS NSInteger class) but have managed to work around that now.