tiamat
tiamat

Reputation: 961

swift Local notification pop up and no badge

I'm trying to popup a local notification on my app, but it remains on the notification center and increment the badge number even if I ask for badge number to 0.

here is my code:

 application.cancelAllLocalNotifications()
    var localNotification = UILocalNotification()
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 5)
    localNotification.alertBody = "Hello World"
    localNotification.alertAction = "Add expense"
    //localNotification.timeZone = NSTimeZone.defaultTimeZone()
    localNotification.applicationIconBadgeNumber = 0
    localNotification.soundName = UILocalNotificationDefaultSoundName
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

how can I generate a popup, with sound (currently there's no sound) without any badge on my app icon ?

EDIT: I enabled notification for my app with popup option...

EDIT2: I also added the following in my appDelegate

if(UIApplication.instancesRespondToSelector(#selector(UIApplication.registerUserNotificationSettings(_:)))) {
    print("enable local notif")
        UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
    }

Upvotes: 1

Views: 761

Answers (1)

ashmi123
ashmi123

Reputation: 710

Firstly Clear that Local notification not provide any sound,badge and popup.You get notification but not alert any sound or badge,you can check that notification Come in background as you slide the notification from top.

Also If you are using Webservice(php API) for the notification then you can Send Sound from there you get the sound alert. Your sample PHP code payload is specifying 'default' as the sound to play. If you want to play a custom sound for Local Notification, make sure the sound file is in the application bundle.

$payload['aps'] = array('alert' => $message, 'badge' => 0, 'sound' => 'bingbong.aiff'

Upvotes: 1

Related Questions