簡體   English   中英

iOS設備令牌是否在括號內提供推送通知

[英]iOS device token for push notification inside brackets or not

當我在deviceToken上執行NSLog時,該字符串在方括號中顯示為"<0000 ... 0000>" 但是所有在線教程都顯示數字/字符串,沒有任何括號< ... > 那么在保存deviceToken時應該刪除括號嗎? 是的,它們確實得到了保存在我服務器上的方括號。 如果要卸下支架,執行該操作的代碼是什么?

-(void)application:(UIApplication *)application
 didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString* deviceTokenString =[NSString stringWithFormat:@"%@",deviceToken];    
    NSLog(@"Device token is %@",deviceTokenString);
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken  {
    NSString * deviceTokenString = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"content---%@", deviceTokenString);
} 

這是另一種選擇

NSString * deviceTokenString = [[[[deviceToken description] 
                        stringByReplacingOccurrencesOfString:@"<"withString:@""] 
                       stringByReplacingOccurrencesOfString:@">" withString:@""] 
                      stringByReplacingOccurrencesOfString: @" " withString: @""];


NSLog(@"device token - %@", deviceTokenString);

暫無
暫無

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

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