简体   繁体   English

使用运行iOS 7.1的iPhone 5s时,设备令牌为nil

[英]Device token is nil when using iPhone 5s running iOS 7.1

my app got rejected by the apple review team. 我的应用程序被苹果评论团队拒绝了。 They send me a crash file that says: 他们给我发送了一个崩溃文件,上面写着:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000



2 CoreFoundation  0x2e8c0e40 +[NSException raise:format:] + 108
3 Foundation      0x2f1e7500 -[NSString stringByAppendingString:] + 84
4 TheApp          0x000aaa3a -[UserSignInViewController userEmail:userPassword:]     (UserSignInViewController.m:175)

This crash occurs when logging in to the app, using an iPhone 5s running iOS 7.1. 使用运行iOS 7.1的iPhone 5s登录到应用程序时,会发生此崩溃。

First of all I get the device token via "didRegisterForRemoteNotificationsWithDeviceToken:" in the AppDelegate.m (first time the app is launched) and save it tmp. 首先,我通过AppDelegate.m中的“ didRegisterForRemoteNotificationsWithDeviceToken:”获取设备令牌(首次启动该应用程序)并将其保存为tmp。 to a static variable: 到一个静态变量:

NSString *tmpDT = [[[NSString stringWithFormat:@"%@",deviceToken]
                    stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];

// Set tmp device token in DataStorage

[PSDataStorage setDeviceToken:tmpDT];

When the user is logged out and wants to login to the app an URL with parameters is created by appending strings: 当用户注销并要登录到应用程序时,将通过附加字符串来创建带有参数的URL:

//...

// get device token from DataStorage

NSString *deviceToken = [PSDataStorage getDeviceToken];

NSString *fullURL = @"https://.../.../....json?email=";
fullURL = [fullURL stringByAppendingString:userEmail];
fullURL = [fullURL stringByAppendingString:@"&pw="];
fullURL = [fullURL stringByAppendingString:userPassword];
fullURL = [fullURL stringByAppendingString:@"&client=ios"];
fullURL = [fullURL stringByAppendingString:@"&device_token="];
fullURL = [fullURL stringByAppendingString:deviceToken]; 

UserSignInViewController.m:175 references to: UserSignInViewController.m:175引用至:

fullURL = [fullURL stringByAppendingString:deviceToken]; 

It seems like the deviceToken is nil. 似乎deviceToken为nil。 I'm also handling the case, that an user disabled PNs via: 我也在处理用户通过以下方式禁用PN的情况:

didFailToRegisterForRemoteNotificationsWithError

I'm really confused. 我真的很困惑

I hope you guys can help me out. 我希望你们能帮助我。

A device token is NSData , if you want to use it in a string you'll need to convert it to hexadecimal format. 设备令牌是NSData ,如果要在字符串中使用它,则需要将其转换为十六进制格式。 Try using the NSData+APNSToken cocoapod to convert the NSData to a NSString . 尝试使用NSData+APNSToken cocoapod将NSData转换为NSString

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM