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.

First of all I get the device token via "didRegisterForRemoteNotificationsWithDeviceToken:" in the AppDelegate.m (first time the app is launched) and save it 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:


// 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:

fullURL = [fullURL stringByAppendingString:deviceToken];

It seems like the deviceToken is nil. I'm also handling the case, that an user disabled PNs via:


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. Try using the NSData+APNSToken cocoapod to convert the NSData to a NSString.

Related Articles
You Might Also Like