Reputation: 873
If I've my app closed and I send a push notification like this:
{
"alert" : "Hello, world!",
"sound" : "default"
}
My app receives push notification correctly. But if I send this:
{
"aps" : {
"alert" : "Hello, world!",
"sound" : "default"
}
}
My app never show the notification.
If my app is opened I received this last notification correctly in delegate didReceiveRemoteNotification userInfo: [NSObject : AnyObject]
Why iOS 8 is not parsing this last notification and showing it like a notification?
Upvotes: 0
Views: 256
Reputation: 369
For Objective C. Take a look That have you Received The Json Correctly. For First Option You have used i think code like this
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
}
This Will Receive a dictionary That you have. But Second Option You have sent an Array whose First index has an Dictionary So Replace NSDictionary with NSArray Then Receive The array
first index & Retrieve The dictionary like this
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSArray *)notification {
......
}
For Swift This code has worked For me.
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
println("Push Received")
println(userInfo)
println(userInfo["aps"])
var state: UIApplicationState = application.applicationState
if state == UIApplicationState.Active {
println(userInfo)
println(userInfo["aps"])
var alert2 = UIAlertController(title: "Push", message: "Received", preferredStyle: UIAlertControllerStyle.Alert)
alert2.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in
}))
}
Upvotes: 0
Reputation: 6795
Without code that actually sends a notification it is not clear totally where is the problem, because if you use some library or wrapper it may add aps
entry itself. Right now, you should continue sending notifications as in the first example and you will also get them in the didReceiveRemoteNotification userInfo: [NSObject : AnyObject]
Upvotes: 1