Not receiving any push notification in iPhone
Asked Answered
T

8

25

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.

Tigerish answered 22/4, 2013 at 5:32 Comment(1)
NOTE, be aware of the BATTERY GOTCHYA ... read carefully here developer.apple.com/library/archive/technotes/tn2265/… at "If the energy or data budget for the device has been exceeded...."Duel
S
32

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

Systemize answered 22/4, 2013 at 6:18 Comment(19)
Tons of Thanks Hinta...i figure it out,there was space in device token.Tigerish
just spent >1hr with my App in foreground trying to realize why I'm not receiving push notifications... oh damn!!! :)))Luzern
@Nitin are you using development certificate and provisioning profile and for creating ipa ?Systemize
You might choosing different certificate and provisioning profile for release and development mode.Systemize
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.Barbra
@Barbra have you used the same certificate .pem file at the server end ?Systemize
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.Barbra
but, my application is close, i am not getting APNS. If my app is in background im getting APNS. any solutions for this?Scutter
@Anilkumar The device token might be cleared from the server side there must be some session concept in your appSystemize
we, figured out, its issue due to silent mode of APNS. Thanks for your response @DivzScutter
@Anilkumar, what kind of issue it was?Overplay
@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.Overplay
@Divyamshukla : You saved my another day! I was struggling where I'm going wrong in code!Trackless
@JayprakashDubey :)Systemize
i recieived notificatuion on cansole but not display in notification view. So please give me solutionHowlan
is your application is on forground ? @VikasDhasalSystemize
@VikasDhasal press home button when you will receive push it will be shownSystemize
After spending 2hours time I found this solution, my app is in foreground thats why notifications are not received.Jugurtha
@Jugurtha enjoy :)Systemize
D
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 flakey regarding battery state of the phone. (Further, some of the stuff mentioned in that article, which is very old, is now plain wrong.) Basically you will often JUST 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!!

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

  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 very confusingly-named "development, sandbox" push notifications are ONLY for "tethered phone builds".

(And as mentioned to add more confusion, the "development, sandbox" push notifications often just don't work: although update for 2024 they seem more reliable these days.)

Read more here! https://mcmap.net/q/538629/-ios-push-notifications-using-tls-certificate-vs-using-authentication-tokens

Duel answered 8/3, 2020 at 16:28 Comment(0)
G
6

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

Glaciology answered 22/4, 2013 at 5:37 Comment(4)
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 developer.apple.com/library/ios/#DOCUMENTATION/…Glaciology
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.Tigerish
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.Glaciology
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)Tigerish
C
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)
    {
    }
}
Caracara answered 22/4, 2013 at 6:17 Comment(2)
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.Tigerish
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.Caracara
F
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.

Floyfloyd answered 22/4, 2013 at 6:20 Comment(1)
I have already tried it with Banner & Alert. The app is being listed in NotificationCeter.Tigerish
D
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.

Deliquescence answered 30/6, 2016 at 13:17 Comment(1)
' APN Tester Free' Not available in IndiaCrayton
D
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)
Dubois answered 22/4, 2017 at 14:40 Comment(1)
your payload may be blank values you can get from userInfo.Systemize
S
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.

Striper answered 11/12, 2019 at 1:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.