2012-12-07 164 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等,但不能讓我的最後一個開發證書超時後,我重新創建它。應用程序工作數月之前。

最終什麼幫助真的從電話中擦除並重新安裝它。 似乎一些存儲的數據有點損壞...

請記住,應用程序然後將註冊一個新的令牌。