iOS APNs message One can not receive the solution directly

Source: Internet
Author: User
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);
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.