Not receiving any push notification in iPhone

2019-01-17 07:14发布

问题:

I have made a sample PushTest app for Push Notification using this tutorial.

And using above tutorial I got the message that 'PushTest' would like to send you Push Notification (exactly once) and after that I delete the app from iPhone, restart the iPhone but unable to get the same message again.

I have run the script sample.php (updating the changes suggested) and got the message 'connected to APNS' & 'your message send'.

But I didn't receive any single push notification.

Please guide me where I am wrong?
Or what shod I try for push notification receive.

回答1:

You will not receive Push only in 2 cases

1.) If your application is in foreground.

2.) you device token is not valid for receiving the push notification please check both the condition if you still do not receive push please let me know. Thanks



回答2:

Make sure you are using push notification enabled provisioning profile. and then check if you are sending token to server.



回答3:

I have followed the same tutorial.

Make sure your app is listed in notification center, and it's alert type is anything but not none.

You need to check your notification in 3 conditions,

When your app is open, in background, and when closed.

For that, you need to in check these methods

// To Register your device token
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

//If your app is not able to register
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{}

//Your app receives push notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

    UIApplicationState state = [application applicationState];

    // If your app is running
    if (state == UIApplicationStateActive)
    {

        //You need to customize your alert by yourself for this situation. For ex,
        NSString *cancelTitle = @"Close";
        NSString *showTitle = @"Get Photos";
        NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
                                                            message:message
                                                           delegate:self
                                                  cancelButtonTitle:cancelTitle
                                                  otherButtonTitles:showTitle, nil];
        [alertView show];
        [alertView release];

    }
    // If your app was in in active state
    else if (state == UIApplicationStateInactive)
    {
    }
}


回答4:

Please check in your device's Settings if notifications for the application are on and ensure that the type of the notification is not 'None' in Notification Center.



回答5:

Make sure, that you select right provision profile

and that your app is minimized. If app's not minimized use

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"info %@", userInfo);
}

Other useful information about issues.

For TESTING pushes you can use APN Tester Free. Attention: insert token WITH spaces.



回答6:

I was not getting anything in:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any])

But my compiler stopped on breakpoint in

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)