簡體   English   中英

如何獲取用戶的設備令牌以進行推送通知

[英]how to get the users` device token for push notification

我正在使用推送通知來通知用戶。 我已經在真實設備上成功測試。 現在,我嘗試將其集成到我的應用程序中。 我想知道如何獲取用戶的設備令牌。

我想我可以通過http或ftp將設備令牌發送到我的服務器,並將它們存儲在db中。 服務器負責將通知推送到提供令牌的所有設備。 這是做這項工作的正確方法,還是有更好的方法?

您可以使用以下代碼打印設備令牌:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
    NSLog(str); 
}

有關更多信息: 單擊此處:Tutorial_Programming Apple Push Notification Services

是的,您需要在服務器端處理它,並在應用程序圖標旁邊看到badge編號。 您可以使用一個PHP文件(或您熟悉的任何文件),該文件在用戶每次啟動應用程序時都接收令牌,然后在數據庫中將徽章圖標設置為0。 對於您發送的每條新通知,您都將該字段增加+1。 希望這對您有用。

如果仍然沒有獲取設備令牌,請嘗試放置以下代碼,以便為推送通知注冊設備。

它也可以在ios8或更高版本上使用。

如果__IPHONE_OS_VERSION_MAX_ALLOWED> = 80000

if([UIApplication responsesToSelector:@selector(registerUserNotificationSettings :)]){UIUserNotificationSettings *設置= [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound類別:無]; [[UIApplication sharedApplication] registerUserNotificationSettings:設置]; [[UIApplication sharedApplication] registerForRemoteNotifications]; }其他{[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];

}其他

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; 萬一

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM