未收到推送通知

时间:2012-12-07 11:45:09

标签: iphone ios apple-push-notifications

我正在我的应用中实现推送通知,一切似乎都很好,但我的设备没有收到推送通知。

我从上面的网址发出通知后得到了回复;

“连接到APNS消息已成功发送”。

但之后我的设备上没有通知。请建议我如何解决这个问题。

4 个答案:

答案 0 :(得分:0)

首先查看有效负载,其中描述了推送通知的性质,这意味着它应该是应用图标上的短信或警告还是徽章。所以我们需要在 JSON的格式中正确设置它。先检查一下,

然后

阅读Ray Wenderlich论坛的精彩教程, 当然,你会发现一些错过的领域或步骤,

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

答案 1 :(得分:0)

我收到同样的错误,因为我写错了设备令牌,请检查您的设备令牌@“< XXx XXXX xxx ..>”已更改为@“XXX XXX ..” 或者只需按照步骤

在app delegate中

in didlaunch

// Register for sound and alert push notifications.
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    // Check if the app was launched in response to the user tapping on a
    // push notification. If so, we add the new message to the data model.
    if (launchOptions != nil)
    {
        NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dictionary != nil)
        {
            NSLog(@"Launched from push notification: %@", dictionary);
        //  [self addMessageFromRemoteNotification:dictionary updateUI:NO];
        }
    }


#pragma mark -
#pragma mark Apple Push notifications

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    // We have received a new device token. This method is usually called right
    // away after you've registered for push notifications, but there are no
    // guarantees. It could take up to a few seconds and you should take this
    // into consideration when you design your app. In our case, the user could
    // send a "join" request to the server before we have received the device
    // token. In that case, we silently send an "update" request to the server
    // API once we receive the token.

    NSString* oldToken = [self deviceToken];

    NSString* newToken = [deviceToken description];
    newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];

    NSLog(@"My token is: %@", newToken);

    [self setDeviceToken:newToken];

    // If the token changed and we already sent the "join" request, we should
    // let the server know about the new device token.
//  if ([dataModel joinedChat] && ![newToken isEqualToString:oldToken])
//  {
//      [self postUpdateRequest];
//  }
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    // If we get here, the app could not obtain a device token. In that case,
    // the user can still send messages to the server but the app will not
    // receive any push notifications when other users send messages to the
    // same chat room.

    NSLog(@"Failed to get token, error: %@", error);
}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
    // This method is invoked when the app is running and a push notification
    // is received. If the app was suspended in the background, it is woken up
    // and this method is invoked as well. We add the new message to the data
    // model and add it to the ChatViewController's table view.

    NSLog(@"Received APNS notification: %@", userInfo);
    [self log:[NSString stringWithFormat:@"Received APNS notification: %@", userInfo]];

    UIAlertView* nofity = [[ UIAlertView alloc]initWithTitle:@"APNS" message:@"Test Successfull" delegate:nil
cancelButtonTitle:@"ok" otherButtonTitles: nil];
    [nofity show];

//  [self addMessageFromRemoteNotification:userInfo updateUI:YES];
}



- (NSString*)deviceToken
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"DeviceTokenKey"];
}

- (void)setDeviceToken:(NSString*)token
{
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DeviceTokenKey"];
}

- (NSString*)udid
{
    UIDevice* device = [UIDevice currentDevice];
    return [device.uniqueIdentifier stringByReplacingOccurrencesOfString:@"-" withString:@""];
}

从上面的代码中获取设备令牌。

<强>测试 将设备令牌传递给Push me baby app

答案 2 :(得分:0)

检查以下

  1. 您是否获得了推送令牌?如果是,请删除空格,然后&lt;,&gt;来自推送令牌。

  2. 检查设备是否已连接到互联网

  3. 检查设置 - &gt;中是否启用了通知(横幅广告或弹出广告)通知 - &gt;您的申请 - &gt;选择横幅或提醒(弹出窗口)。

  4. 最有可能的是,任何这都是一个问题。

答案 3 :(得分:0)

一个简单的伎俩: 我遇到了同样的问题,双重检查了所有内容,重新创建了pem等,但是在我的上一次开发模式超时并且我重新创建它之后无法完成它。在应用程序运行数月之前。

最终帮助真正从手机上擦除并重新安装它。 似乎某些存储的数据有点腐败......

请记住,应用程序将注册一个新令牌。

相关问题