Not receiving any push notification in iPhone

依然范特西╮ 提交于 2019-11-28 06:24:28
Divyam shukla

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

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

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)
    {
    }
}

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.

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.

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!