Ios quickly creates local notification after silent notification

I send a silent push notification to my application and then process the contents of the push notification before deciding whether to send a local notification to the user. However, I cannot start a local notification from the application after receiving a silent notification.

Here is my code in appdelegate after running silent notificaiton:

func application(application: UIApplication,
    didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
    fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
        println("Did receive remote with completion handler")

        var localNotification:UILocalNotification = UILocalNotification()
        localNotification.alertAction = "view broadcast messages"
        localNotification.alertBody = "Hello"
        localNotification.fireDate = NSDate(timeIntervalSinceNow: 0)

        localNotification.soundName = UILocalNotificationDefaultSoundName;

        application.scheduleLocalNotification(localNotification)

        handler(UIBackgroundFetchResult.NewData)
}

However, local notification never fires.

I have included location updates, background fetching capabilities and remote notifications.

In addition, when my application is in the background, it listens for location updates, and then alerts the user with local notification in certain situations, which works with similar code.

, didReceiveRemoteNotification?

+4
1

, ,

application.scheduleLocalNotification(localNotification)

UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

, -!

+5

All Articles