已收到APNS通知但未显示

时间:2014-07-28 07:31:53

标签: ios objective-c iphone ipad apple-push-notifications

我正在尝试实现推送。当app处于运行状态时,我会收到推送消息。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

NSLog(@"\n\n\n apns==%@\n\n\n",userInfo);


}

我的问题是,当应用程序未运行时我按下消息意味着仅在应用程序图标上显示徽章计数。它不会显示关闭和查看按钮等警报。即便我预测

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    NSLog(@"\n\n\n\apns==%@\n\n\n\n",launchOptions);
}

我也在设置中检查了 - >通知 - > myApp - >选择徽章,声音,警报

我使用下面的配置:

Mac os 10.9

xcode 5.0.2

ios 7.0

请建议我。

我想要这条消息。

enter image description here

提前致谢。

3 个答案:

答案 0 :(得分:3)

您必须设置警报视图以显示即将到来的推送通知消息,如:

- (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];
    }
}

当你的应用程序处于后台模式或关闭那个经理时,苹果你无法处理它。您必须从设备 - >设置设置警报提示。并且您对显示器进行了徽章,因为您徽章的自动功能会将其计为整数值,以便自动设置。只需从设备设置推送通知设置 - >设置 - >通知中心--->找到您的应用--->选择它并显示如下:

enter image description here

<强>更新

您推送Notificaton Payload JSON格式应如下所示:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    }
}

答案 1 :(得分:1)

当关闭应用并获得推送通知时,推送通知可在launchOptions

中的-didFinishLaunchingWithOptions:参数中找到

您可以通过以下方式访问它:

//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:我对类似问题的回答:Push Notification -didFinishLaunchingWithOptions

答案 2 :(得分:0)

我遇到了同样的问题,我找到了问题并修复了。 您需要检查

上的警报值
{
    "aps": {
         "badge": 1,
         "alert": "your value!",
         "sound": "default"
    }
}

当您致电"your value"时,我认为json_encode为空。