iOS Sending a Push Notification From an iOS App, APNS - ios

Is there anything preventing SENDING a push notification FROM an iOS application? There are reasons for my madness. If so, are there any good examples out there? I have code that should be working and if there is no blocking reason, I will post the code.
I tried on Verizon and AT&T. Would want it over a carrier for now.
Please do not comment on why, etc.
[addition]
This would not be for a public app, testing internal only.

I don't see any reason what this wouldn't work. You'll have to include the push certificate with your application, and your users will have to download a new version of your app every time the certificate expires (which means once a year). You'll also need to send to each device all the device tokens of devices it should send notifications to.
The sending code should be the same as it would be in a server that sends push notifications, but you would have to implement it in objective C.
All in all it doesn't seem like a good idea, since you'll need a server anyway (for each device to get the device tokens of other devices), so it makes more sense that the server will do the sending.

Actually yes - there are a few things that prevent you from sending push notification from iOS.
Even if you manage to install (use in your app) certificates needed to properly connect to Apple's APNS server their policy is to start blocking clients that create many short connections.
So for public app you would need to use a "normal" way of setting up your PHP server that manages communication with APNS. Otherwise many public IP's (devices) using your credentials would lead to blocking your app APNS certificate.
If this would be just for private use then there is no reason not to give it a try.

Related

APN push notifications for chat

I'm trying to add notifications to a private chat app that uses Firebase, unfortunately Firebase has an APN service but it must be configured and needs also a server app to manage it. I'd like to have the user notified when someone is texting him while the app is in the background. The problem is that APN (Apple Push Notifications) requires a server with a certificate and that is ok with me, but I'm looking for a way to send push notifications from an iOS device to another device, I mean device-to-device push notifications and the server has just to relay the messages as they are. In my case the APN server should only relay the messages that it receives from a source device to the destination device. I couldn't find a way to obtain that without writing sever code. I want to use pre-built existing services. Has anybody any idea on how to send push notifications from one device to another without configuring and writing server apps? I tried a workaround using the background fetch iOS feature, but the system si randomly giving my app execution time... and that means that my app could wait hours before being started by the system... so that is not a viable solution. Please help
Ok, probably what I found out could be helpful for others. Actually
what I'm looking for can be directly integrated in the app. You need a library like NWPusher (free on GitHub) which can be imported, and with just a few lines of code and the APN device token you get from the system, it is possibile to implement APN notifications... easily, but most importantly... for free.
UPDATE
Check also APNS framework on GitHub. It's written in Swift 3.0 and it supports the latest features.
You are essentially looking for a messaging / chat API to handle device-to-device communication. You might want to try Pusher or PubNub

How to check authenticity of iOS device

I have an app-server process that needs to check if the device making a request is an actual iOS device. I used to do this by taking advantage of push notifications. The user first authorizes push. Each time the user makes a specific type of request, I push a code to that device with which the app uses to make a second "authenticated" request to the app server. That additional channel of going through APNS would, in a sense, prove the authenticity of the requester's device. This makes it difficult for a person to spoof the request because they would not be able to receive the push notification with the needed code.
Recently though Apple started enforcing the rule that apps cannot require the user to accept push notifications in order to use the app, even though we do not use push notifications for alerts.
Is there any comparable way for my app server to check with Apple that a request is coming from my app on an actual iOS device? Or is this an unrealistic expectation to be able to determine this.
I could not find the article now, but some guys managed to register raspberry pi as a iOS device and receive push notifications via wifi... that I believe would be concrete proof that not even your first "2 way authentication" is really safe...
Now, directly answering, NO, there's no way for your app server to check if the request did come from a iOS device because all info in a TCP/UDP package is 100% "spoofable"...

Is it possible to send push notification from one iOS app to another iOS app?

I am not very familiar with push notifications. But is it possible to send push notification from one app to another? I know you need a server to send notifications but is it possible implement that in an app.
Short answer: No, pushes are sent from a server to a server.
Long answer: Of course, it's not common practice, but lots of fun.
To send out a push notification to an Apple device, you will need to connect with the APNS server and then send your notification in data format. Although this is usually done from a server, it can just as well be done from an iPhone or iPad.
If you want to get going yourself, I recommend reading all the documentation Apple provides on this topic (start here). Everything you need to know is in there, but you will need to pay attention to the details in order to get this to work.
An easier way to get going is by using NWPusher. This is an iOS framework that provides all the tools you need to push from iOS to iOS. It even includes an iOS demo app that does this:
NWPusher - Push from iOS
Just a small warning: In order to push from iOS, you will need to include the push certificate and private key in the app bundle. This is not a secure place to keep such a private key and you definitely don't want your app's push certificate to leak.
Enjoy!

How does the push notification works in the Mobile Device Management in iOS?

I am doing MDM implementation in iOS and I have one server for its implementation.I have gone through the documents and understood the process that we have to undergo.But Simply I don’t understand how it will happen.I have one server and one device.I have my PEM file enrolled in the server.
As the process of MDM says server sends push notification through the device and the information that is present in the message in only the identifying token.Then device is connected to the server and sends an idle message confirming that device is ready for the commands.
My question is how device receives the push notification.If app is in back ground state and it gets a notification to connect to the server is there any method to detect it and send the feedback or is it happening automatically or we have to write some code for it. Also how does the plist (that we get in command) make changes in the settings (unlock to lock) .Do we save it somewhere in the device configuration?
I have got a lot of questions about the command format but did not get anything how the command works.May be I am missing basic iOS coding.please just explain me the above format.
how device receives the push notification.If app is in back ground state and it gets a notification to connect to the server
First of all, you will have to implement server side only for iOS MDM. Client side is implemented by Apple and MDM client is baked into iOS.
As part of OS it dosn't have restriction which usual iOS apps has. It has a persistent channel to APNS and as soon as somebody send a push notification to APNS, the device will receive it through this persistent channel and will start doing what it should be doing.
Also how does the plist (that we get in command) make changes in the settings (unlock to lock) >.Do we save it somewhere in the device configuration?
The answer is the same. You don't have to implement anything on the iOS side. It's all done by Apple- MDM client will get the command, parse it, save it to appropriate places and enforce appropriate policies.

Is there a workaround for APNS Feedback?

The iOS app i developed uses APNS. Locally i could simulate the whole process from saving device tokens, sending push notifications to deleting device tokens with help from APNS feedback successfully. Also in production it worked for a short time.
Now my webhoster closed port 2196. Port 2195 is available, so sending notifications is still possible. I do not want my ios app to get on the blacklist, so is there any other way to register whether a user has deleted my app on their device? Or will i have to look around for another webhoster, who has both ports open? Any suggestions?
You'll have to look for another host or look into 3rd party solutions that have a Feedback API. I know Urban Airship had one (haven't used it in a while) and may be giving access to it freely.

Resources