In the afternoon, our test environment has not received the APNS message (two in the morning). After dealing with the final solution to the problem, record, other code dragon friends See, can also refer to the reference.
There are several specific solutions to eliminate the problem:
1. First make sure to open the current app's message push allow settings. (iphone set inside Open, allow app to receive push message)
2. Print under Devicetoken to see if there is a value, or directly in the following register the success of the function inside dozen a breakpoint, see the program into not come in, one step debugging.
(Generally, as long as Devicetoken has a value, it means that APNs has been registered successfully.) Otherwise, go to research and add the APNS registration function.
At the same time, it should be noted that there is Devicetoken return, also not necessarily real-time received APNS push message (because we have a good greatewall, or network packet loss). Push a few more information, you can receive, generally APNS arrival rate is still possible. )
My program did not print Devicetoken, and the interrupt point in the following function did not come in.
3. To ensure that the current landing mobile phone number only landing app, a mobile phone number of multiple app landing, may also be received.
4. Re-launch the app and log in again. (Means re-registering the APNs)
5. There is no devicetoken words, the current app delete, reload. --I used this approach, with Devicetoken, and then with a APNs push .
After registering successfully, Apple will return to a global unique devicetoken to the handset client, then through the following function, can capture.
-(void) Application: (UIApplication *) application
Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken
{
///Send token to service-side
if (Devicetoken)
{
Currentdevicetoken = [[[Devicetoken description]stringbyreplacingoccurrencesofstring:@ "<" "withstring:@" "]stringbyreplacingoccurrencesofstring:@" > "withstring:@" "]stringbyreplacingoccurrencesofstring:@" "withstring:@" "]; Uialertview *alterview = [[Uialertview alloc] initwithtitle:@ "" Message:currentdevicetoken Delegate:nil Cancelbuttontitle:nil otherbuttontitles:@ "OK", nil]; [Alterview show];
NSLog (@ "devicetoken:________%@", Currentdevicetoken);
}
Registration fails, the following function is used to return the error reason for registration failure
-(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) error
{
NSLog (@ "Register push failed:%@", error);
}