Ruby apns gem returns nil - ios

I'm trying to get the APNS gem to work with my Rails app. I had originally set this up several months ago, and push notifications to iOS devices worked swimmingly. Now, my app is live and I've found that notifications aren't going out anymore. The APNS gem hasn't been updated in some time, so I've tried various later forks of it, all to the same effect.
Here's what I'm doing:
APNS.host = 'gateway.push.apple.com'
APNS.pem = Rails.root + "lib/push_production.pem"
APNS.port = 2195
APNS.send_notification(device_token, "Test send" )
And the result?
=> nil
There's no feedback from any method, no logfile that I can check. I've tried generating and regenerating my certificate; everything seems okay there. I've tried expressing my device token in various ways, without the angle brackets, without spaces between groups of characters... APNS don't care.
Given the number of moving parts involved in this, I know this is a tough question. But can anyone suggest where to look?

The official documentation says this :
If you send a notification and APNs finds the notification malformed
or otherwise unintelligible, it returns an error-response packet prior
to disconnecting. (If there is no error, APNs doesn’t return
anything.) Figure 5-3 depicts the format of the error-response packet.
So it only makes sense that the gem doesn't return anything, because Apple's server doesn't let it know what it's doing. Also if you look at the gem's github page, the given examples do not handle the return value of APNS.send_notification.
Last time I worked with Apple Push Notifications, it pretty much behaved like a black box, not returning anything most of the time.

I believe I've found the answer. After registering an account with Urban Airship, I tried sending a test message to my phone, and again to no avail. But these guys actually have their act together, so they were able to show me the error message! Turns out my device token was invalid. Why? Because it was generated by the sandboxed version of the app.
Yes, my app is in the store, but it turns out that my App Store distribution profile was generated before the push notification entitlement was added to it. So when you run the codesign tool on my executable, it doesn't show the entitlement. Here's an example:
Diomedes:Release-iphoneos aaron$ codesign -dvvvv --entitlements - Tiberius.app
That command should show a plist that contains the key with a value of "production". My release didn't have that key at all.
I was actually forced to generate an all-new distribution profile in the Provisioning Portal, which finally did include the correct entitlements. I haven't been able to test this yet (8 day App Store review, anyone?) but I feel like this is the problem.
P.S. This article on Urban Airship's site was instrumental in helping me.

This worked for me,
Is your sandbox value correct? Use false for production certificates and use true for development certificates.
P. S. https://github.com/tompesman/push-core/issues/27

Related

Issue using Codename One iOS Certificate Wizard, getting error "REST request failed"

I have been trying to generate an iOS certificate from the Codename One Control Center, launched from Intellij. Every time I submit my apple iOS developer credentials, and then input the 2 factor authentication code, it returns with this error:
REST request failed due to internal CLI failure. See server error log.c5307525-1805-4360-d4ca9d46cad0
I enrolled in the Apple Developer Program, and I believe I've agreed to all of the Apple Developer agreements and such, and I have exactly one device registered, as well as that one device set as the trusted device, so it receives the 2 factor authentication notifications. I'm also not sure where I am expected to be able to see the "Server error log" as I have searched around for that.
I've only been able to find 2 other cases that seem similar to mine but neither give me a clear idea of what the problem is or how to fix it. They do however seem to resolve their problems. I really don't have any more ideas as to what the problem could be.
Codename One IOS signing
Unable to Login to iOS Account from CodeNameOne
Another odd thing about this problem is that usually I get this error after being prompted to input the 2-factor authentication code, but sometimes I'm never prompted to input the code before getting the error, yet I will still receive the 2-factor authentication code text message on my phone despite there being nowhere to use it.
Any help is appreciated.
I have made some updates to the certificate wizard to try to work around this issue. Please give it another try. If you run into another problem, please post the error message again, and I'll look it up in the logs.
Ok so after looking around a bit further, I was finally able to find a git issue post that seemed similar to mine, and at the very end of the thread (linked below), someone mentioned that you need to be signed into that apple id on the device, not just have it as a trusted device. My iOS phone was showing up in the account because I was logged into the Apple Developer App, but this is not enough. Thanks for helping.
https://github.com/codenameone/CodenameOne/issues/2779

Cannot get push notifications with PEM file

I may sound like noob but I faced a problem and not able to find the solution. I searched all over the google and nothing.
Here is the problem.
I have an app that should receive push notifications. Until iOS 10 everything worked perfect, but now I am not able to receive notifications with my PEM file, instead I can receive them with my P12 file, but PHP won't accept P12, so I am stuck.
I have created my pem-s using this thread link
In my app code is written based on this link
One more thing.
I have tested my push notificatoins also using this website http://pushtry.com/ and in case I use PEM file and TEXT mode, I can receive push, but PEM file and JSON mode does not work. P12 works with both.
I don't know what to do. Please helppppp!!!!
I have found a solution, hope it will solve your problem.
First, use this link: http://apns-gcm.bryantan.info/ and follow their instructions , instead of pushtry.com
Implement all the methods related to remote notifications and make sure all these are updated.
If by mistaken or accidentally your app not enabled notifications for background mode then refer this link: https://www.iphonemanager.org/ios-11-notifications-not-working.html
I have followed these instructions and at my end apns is working.

Push notifications issues: key,failed/message not reach

I'm still new to iOS dev.
And I'm very, very new to whole APNS idea. I followed many tutorials, and didn't go so well.
I'd like to ask some questions.
Can I use same .certSigningRequest file for dev/dist/apns certificates? Does it matter if some of this certificates from this .certSigningRequest have been revoked?
When I export my key in keychain to .p12 file, can I use this one for both dev/distribute version?
If my server open port 2195, by giving .pem generated from above cer, my server should be able to send push message, right?
How can I unsubscribe/unregister from my device and/or from server/apns service? I mean when I need to remove, and try to build&run the code again.
4.1 How does
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
really work? Does it tell apns not to send message/just turn it off? How can my server/provider know if device need to unsubscribe?
I find this tutorial really useful: http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
And here some questions I have about what I encountered.
1. The sample app from the tutorial worked fine, using both my laptop & my server to send a message. But after a few days, it doesn't. (the response is still 'Connected to APNS Message successfully delivered', but the message never reach my device)
What could be the cause? My friend have revoked a dev cert? (I shared acc. w/ my friends) Or I reinstall the app? I also tried method unregisterForRemoteNotifications & register again, but nothing happens.
2. I also tried https://apphq.shephertz.com for a provider. This one requires .p12 key file in their format. (link) I have another project (this one is unity) register apns thru the app. It seems fine since I can see device token & user store in the web. But when I tried to send message, I got an error, like
iOS KeystoreException Device ID : <my-device-token> : Invalid keystore password! Verify settings for connecting to Apple... Does anyone know what this mean?
Sorry for my poor English.

APNS not received after server migration

Our iOS app successfully implemented APNS. Sometimes its not getting received but almost 90% of time its ok.
Now we are required to migrate the whole server-side (which is written in PHP) codes.
After few hours, everything was done and thought migration was completed (all webview was correctly shown, user's data etc.). However, when my colleague try to send push notification to my iOS app, it failed to receive. The server log stating that the APNS was successfully sent and no errors. Interestingly, when he try to send APNS through web browser (hit the URL to send the command), it's successfully received.
Now we don't know where to go from here and don't know what to do. Are we missing some process required in the case like this? For example, should we re-create Certification files for APNS if we want to migrate the whole system? Is there any iOS code at all to modify when the server was migrated? (Other than referral to the server URL. We have already checked that)
I know that the question is too vague but it's just happened and we really can't think of any reason. If there's any guidance for server migration for APNS, it would totally appreciated.
Thanks in advance.
You're right, way too many unknowns to give you a straight-forward answer :)
But, if I understand correctly, when you trigger the PHP from a web browser, the push works. When it's triggered via command line, it doesn't.
Make sure that the user who is executing your script via command line belongs to a group that has enough rights to execute all the statements in your PHP script. For example, if you're using the fwrite command, the user executing the script must belong to a group that has access to the file system.

APNS - Multiple Certificates in one file (dev and production)

We are developing an iPhone application as well as an iPad application.
Both of them do have different Bundle Identifieres but should receive Push Notifications.
The certificates are generated like documented in apples programming guide.
So, due to the fact that we do have four ceriticates (APNS-Dev-iPhone, APNS-Prod-iPhone, APNS-Dev-iPad, APNS-Prod-iPad) I am wondering how to combine those certificates into one file?
The problem is, that on the backend side we are only storing the device token of a user. It is easy to decide whether we are working in development mode or not,but how should I decide which certificate to use - the ipad one or the iphone one?
Due to the fact, that we only have the device token, we do not know if the user is using the iPad application or the iPhone one, so we cannot assume which certificate to use when connecting to the apns apple server.
Any suggestions on how to handle this issue? Should we store more information - for example the device the user was sending the device token from? Or is there any easier way to combine all the certificates into one file and send it over to the apns apple server?
Thanks in advance, I would appreciate any help!
I have a similar issue and have not found a solution that I find satisfactory.
The way that we handle it is similar to what tGilani described. We have to store some kind of identifier that distinguishes which certificate to send a notification through for a particular device token.
Our issue goes further in that we might possibly have to send notifications to different applications altogether. These applications will probably be on a per tenant basis. Thus creating a universal application and one certificate will not work for us.
It would be terribly convenient if I could find a way to combine multiple p12 files into one jks and continue to use one of the Java PNS or Java APNS projects to send notifications.

Resources