24

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.

Migol
  • 8,161
  • 8
  • 47
  • 69
Idiot
  • 261
  • 1
  • 2
  • 6
  • **NOTE, be aware of the BATTERY GOTCHYA ...** read carefully here https://developer.apple.com/library/archive/technotes/tn2265/_index.html at *"If the energy or data budget for the device has been exceeded...."* – Fattie Mar 08 '20 at 16:24

8 Answers8

31

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

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Divyam shukla
  • 2,038
  • 14
  • 18
  • Tons of Thanks Hinta...i figure it out,there was space in device token. – Idiot Apr 22 '13 at 07:03
  • 7
    just spent >1hr with my App in foreground trying to realize why I'm not receiving push notifications... oh damn!!! :))) – Roman Mar 08 '14 at 12:32
  • @Nitin are you using development certificate and provisioning profile and for creating ipa ? – Divyam shukla Jun 11 '15 at 02:47
  • You might choosing different certificate and provisioning profile for release and development mode. – Divyam shukla Jun 11 '15 at 02:57
  • i am using development certificates.. and development provisioning profiles. but in app id i have enabled development push notifications. i have followed Ray wenderlych tutorials... i have created ipa file in both ways. in development and in distribution. in distribution i have created production certificates and created ad hoc provisioning profiles but still didnt get my notifications working.. for the time my notifications are working. – Nitin Jun 12 '15 at 06:05
  • @Nitin have you used the same certificate .pem file at the server end ? – Divyam shukla Jun 12 '15 at 08:29
  • yeah its same. i have deleted all info from server and from my keychain.. then created all. but still same issue dun know whats the issue.. right now notifications are working when i pick .app file from my bundle. – Nitin Jun 12 '15 at 09:59
  • but, my application is close, i am not getting APNS. If my app is in background im getting APNS. any solutions for this? – Anilkumar iOS - ReactNative Jun 19 '15 at 09:32
  • @Anilkumar The device token might be cleared from the server side there must be some session concept in your app – Divyam shukla Jun 24 '15 at 14:55
  • we, figured out, its issue due to silent mode of APNS. Thanks for your response @Divz – Anilkumar iOS - ReactNative Jun 25 '15 at 09:10
  • @Anilkumar, what kind of issue it was? – Hemang Jan 12 '16 at 10:21
  • @Divz, push notification is the magnificent issue with me, I received it throughly or stop receiving it suddenly. What to do for this case? Btw, I'm running an iOS app with In House provision profile. Everything is setup properly and can be working without making any kind of change. – Hemang Jan 12 '16 at 10:22
  • @Divyamshukla : You saved my another day! I was struggling where I'm going wrong in code! – Jayprakash Dubey Jul 15 '16 at 06:21
  • @JayprakashDubey :) – Divyam shukla Jul 20 '16 at 07:32
  • i recieived notificatuion on cansole but not display in notification view. So please give me solution – Vikas Aug 03 '17 at 10:18
  • is your application is on forground ? @VikasDhasal – Divyam shukla Aug 11 '17 at 11:37
  • @VikasDhasal press home button when you will receive push it will be shown – Divyam shukla Aug 11 '17 at 12:45
  • After spending 2hours time I found this solution, my app is in foreground thats why notifications are not received. – MinnuKaAnae Sep 19 '18 at 08:16
  • @MinnuKaAnae enjoy :) – Divyam shukla Sep 19 '18 at 10:15
7

BE AWARE OF THE BATTERY ISSUE, WHICH BLOCKS YOU FOR ONE DAY OR MORE

Never start testing pushes in development mode (tethered phone) unless the phone is FULLY CHARGED.

https://developer.apple.com/library/archive/technotes/tn2265/_index.html

If your notification payload contains the content-available key, your app will receive the notification if iOS or OS X determines it is energy-efficient to do so. If the energy or data budget for the device has been exceeded, your app will not receive any more notifications with the content-available key until the budget has been reset. This occurs once a day and cannot be changed by user or developer action.

In general, notifications (particularly when you are tethered) are incredibly flakey regarding battery state of the phone. (Also, some of the stuff mentioned in that article, which is very old, is plain wrong.) Basically you often JUST WILL NEVER GET notifications if your phones enter "don't get notifications because of battery" mode - and it can go on for days.

Notifications do (or did) prefer cellular WTF!!!

On iOS, push notifications use the cellular data network whenever possible, even if the device is currently using Wi-Fi for other network activity such as web browsing or email. However, the push service will fall back to Wi-Fi if cellular data service isn't available.

This has changed a lot with different iOS versions but it's a huge hassle.

>>>>> !!! CRITICAL TIP !!! <<<<<

Don't forget that:

  1. Build to a tethered phone. You will only get the "sandbox, development" push notifications. BUT THOSE BARELY WORK - THEY ARRIVE VERY LATE, DO NOT WORK IN SOME REGIONS, AND SO ON. THEY ARE SO FLAKEY THEY ARE USUALLY NOT WORTH TRYING.

  2. Increase build number, build normally for Test Flight, send to test flight, and then install from Test Flight. You will now get CORRECT, NORMAL APPLE PUSH NOTIFICATIONS.

Very confusingly you !!DO!! get REAL push notifications on development Test Flight builds.

That is to say - when you build to TestFlight you DO GET exactly the same "real" push notifications as for actual apps published on the app store and used by your public users - real, true, APNS push notifications.

The incredibly confusingly-named "development, sandbox" push notifications are ONLY for "tethered phone builds". (AND, to add confusion on confusion, the "development, sandbox" push notifications are very unreliable, so you never really know if they are working or not.)

Read more here! https://stackoverflow.com/a/60550859/294884

Fattie
  • 27,874
  • 70
  • 431
  • 719
6

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

Saqib Saud
  • 2,799
  • 2
  • 27
  • 41
  • 2
    are you using same certificate to generate SSL and provisioning profile? it they are not the same push notification wont work. Also verify if you successfully connect to APNS http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html – Saqib Saud Apr 22 '13 at 05:49
  • saqib: I am able to run the app and its sure using APNS profile and also getting the Device Token in didRegisterForRemoteNotificationsWithDeviceToken method. i got the alert 'PushTest' would like to send you PusNotification' one time only, so its sure that I am using right profile. – Idiot Apr 22 '13 at 05:52
  • im sure you are using pushnotification enabled profile. But you might not be using the same CSR on client side and server side. which is usually the reason for pushnotification to not work. – Saqib Saud Apr 22 '13 at 06:01
  • Thanks saqib....can u suggest me how can i verify the same(you might not be using the same CSR on client side and server side) – Idiot Apr 22 '13 at 06:08
2

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)
    {
    }
}
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
  • Hi Hinta, the method - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo is not being called in my case. and all the others things are correct. – Idiot Apr 22 '13 at 06:32
  • 1
    I guess, you must have hardcoded your device token in simplePush.php. So there is no issue of registering your device. Now try to figure out why are you not receiving push notification at device end. – Baby Groot Apr 22 '13 at 06:42
1

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.

Yogi
  • 3,578
  • 3
  • 35
  • 56
  • I have already tried it with Banner & Alert. The app is being listed in NotificationCeter. – Idiot Apr 22 '13 at 06:31
1

Make sure, that you select right provision profile 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.

Nike Kov
  • 12,630
  • 8
  • 75
  • 122
0

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)
0

I ran into a similar issue. Everything was done correctly in the code. I was running the app with a development profile and push notifications on the server (iOS) pointing to production. Make sure your provisioning profile matches the server setting(Sandbox vs. Production). You can also make sure your device is registering correctly.

Manish Jain
  • 9,569
  • 5
  • 39
  • 44