2012-12-07 165 views
1

我在我的应用中实施推送通知,一切似乎都正常,但推送通知未收到我的设备。未收到推送通知

从上面的URL发出通知时,我收到了响应;

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

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

回答

0

在第一次检查出你载荷描述你的推送通知的性质意味着它是否应该短信或警报或应用程序图标徽章。所以我们需要在JSON的合适的设置。检查出来首先,

然后

通过这个漂亮的教程雷Wenderlich论坛, 你一定会发现一些小错过的或步,

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

+0

我已经尝试了所有上述的事情,但没有进展。 –

+0

我以前遇到同样的问题,所以我尝试着重复创建新的CSR和PEM文件以及分配新配置文件的过程,并完成了它。我会建议再次通过冷静的每一步。 – iShwar

0

我得到了同样的错误,因为我正在写错误的设备令牌,请检查您的设备令牌@“< XXx XXXX xxx ..”“更改为@”XXX XXX ..“ 或仅按照步骤

在应用程序委托

在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

0

检查以下

  1. 您是否获得了推送令牌。如果是,请从推送令牌中删除空格,然后从中删除> <。

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

  3. 检查通知是启用(或横幅或弹出式) - >通知 - >您的应用程序 - >选择横幅或警报(弹出)。

很可能,任何这些都会成为问题。

0

一个简单的把戏: 我有同样的问题,双重检查一切,重新创建pem等,但不能让我的最后一个开发证书超时后,我重新创建它。应用程序工作数月之前。

最终什么帮助真的从电话中擦除并重新安装它。 似乎一些存储的数据有点损坏...

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