freshplanet / ANE-Push-Notification

Air Native Extension (iOS and Android) for Push Notification
Apache License 2.0
205 stars 104 forks source link

Unable to get Local Notifications to trigger #69

Closed skizzo closed 7 years ago

skizzo commented 9 years ago

Hi, first of all, thanks for your ANE, and most of all, thanks for being so quick with making it 64 bit compatible. I don't want to use Push Notifications in my app, just Local ones. Therefore, I havent registered anything special at Google or Apple Developer Center. I followed the steps you mention in your readme (adding all the stuff to my application.xml) and the app starts fine on my iOS 8 device (ad-hoc packaging) and even says that push notifications are supported, but unfortunately, the notifications are never triggered after suspending the app.

My code in relatively simple:

private var testPush:PushNotification;
private function sendTestPush():void
{
    this.testPush = PushNotification.getInstance();
    if (this.testPush.isPushNotificationSupported)
    {
        //  this is being executed on my iDevice
        var timeNow:int = new Date().getTime() / 1000;
        var timeTrigger:int = timeNow + 10; // 10 seconds after launch
        this.testPush.sendLocalNotification ( "This is a notification!", timeTrigger, "Notification header", 0, 20 );
    }
}

What am I doing wrong? Thanks!

skizzo commented 9 years ago

bump

kerike commented 8 years ago

Hi,

I have been using this ane for along time, and all worked perfectly. I am working on a new application and I need local notifications, so I tried it again and this time it did not worked.

I changed the air version, manifest file, tried different ane version, and still nothing. Then I had an idea to compare this project to my other working ones. All was the same, and still the local notifications were not working.

Then I had a crazy idea to import the Facebook.ane, and everything started working. So try it out. Maybe that fixes your problem.

brotherslab commented 8 years ago

HI @skizzo, Make sure you set this.testPush.setIsAppInForeground(false); on application deactivate. And on activate set this.testPush.setIsAppInForeground(true); To handle application activate and deactivate use: NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, onActivate); NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, onDeativate);

This worked for me, otherwise local notifications is nor showing.

kerike commented 8 years ago

So, my first post solved my problems on Android. But then I had some problems getting this to work on iOS. After searching here and there I found a solution. Before you try to send local notifications you need to register your device, as you would for push notifications. This is the case I think for iOS 8+.

if(RemoteNotifier.supportedNotificationStyles.toString() != "") { _preferredStyles.push(NotificationStyle.ALERT, NotificationStyle.BADGE, NotificationStyle.SOUND); _subscribeOptions.notificationStyles = _preferredStyles; _remoteNot = new RemoteNotifier(); _remoteNot.subscribe(_subscribeOptions); }

After pressing OK, the local notifications started working.

Hope this will help someone.

skolesnyk commented 8 years ago

@kerike , the user has to approve local notifications as well?

kerike commented 8 years ago

This is the only way I got it to work on iOS 8 and 9. Maybe I missed something...but I had to launch an app and this is the way I got it to work. If someone did manage to get it to work without this little hack, please comment.

This is where I got the idea from:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

In iOS 8 and later, register for notification types, as described in Registering for Notification Types in iOS. (In OS X and earlier versions of iOS, you need register only for remote notifications.) If you already registered notification types, call currentUserNotificationSettings to get the types of notifications the user accepts from your app.

fhassanat commented 8 years ago

kerike got it right. You have to subscribe via remoteNotifier, even if you are not using Push Notification. Cheers kerike.