问题
I am trying to implement pushnotification. I get pushed message when app is running state.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"\n\n\n apns==%@\n\n\n",userInfo);
}
my problem is when I pushed message when app is not running means badge count only show on the app icon. It will not display the alert like close and view buttons. Even I cont predict
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"\n\n\n\apns==%@\n\n\n\n",launchOptions);
}
I checked also in settings --> Notifications --> myApp --> choose badges, sounds, alerts
I'm using config below:
Mac os 10.9
xcode 5.0.2
ios 7.0
Please advice me.
I want this message.
Thanks in advance.
回答1:
You have to setting Alert view for Displaying your coming Push notification Message like:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState == UIApplicationStateActive)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"App Notification" message:[NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
when your application in Background Mode or close then that manager by apple you can't handle it. you have to setting Alert prompt from device-->setting. And you badge Display because that automatically functionality of you badge count it's an integer value so that setting automatically. just set push notification setting from device--> setting-->Notification Center--->find your App--->select it and that display like:
UPDATE:
Your push Notificaton Payload JSON formate should look like this:
{
"aps": {
"badge": 10,
"alert": "Hello world!",
"sound": "cat.caf"
}
}
回答2:
When app is closed and it gets a push notification then the push notification is available in the launchOptions
parameter in -didFinishLaunchingWithOptions:
You can access it this way:
//when app is closed initially but launched after tapping on the push notification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions) { //launchOptions is not nil
NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (userInfo) { //userInfo is not nil
NSLog(@"%@",userInfo);
}
}
return YES;
}
//when app is in background or active
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"%@",userInfo);
}
ref: my answer on a similar question: Push Notification -didFinishLaunchingWithOptions
回答3:
I just got same problem and I have found issues and fixed. You need to check value of alert on
{
"aps": {
"badge": 1,
"alert": "your value!",
"sound": "default"
}
}
I think "your value"
is null when you call json_encode
.
来源:https://stackoverflow.com/questions/24990435/apns-notification-received-but-not-display