iOS push notification size limit and chat application - ios

we're doing chat application for mobile phones using push technology.
The idea is that messages are sent in pushes, so that we keep battery life, avoiding background loop with constant requests to server.
Currently the main problem is iOS message limitation of payload to 256.
Has anyone encounter this problem? What would be the best way to solve it?

Building a chat application using push notification is not a good idea, because push notification is not intended to deliver data, so payload is not your main issue, since there is no guarantee of delivery of push notifications according to apple:
Delivery of notifications is a “best effort”, not guaranteed. It is
not intended to deliver data to your app, only to notify the user that
there is new data available.
Thus you need to use something else until iOS7 is released, because iOS 7 has new background fetching modes, unfortunately I can explain more due to the NDA, so you can log to apple's forum and read about that.
Until that you cant start with Socket based iphone app awesome tutorial by Cesare Rocchi.

What you should do is to instead send an identifier to distinguish the data in the push message, and then have the application download it once the message is opened.

Related

Server sends data while iOS app is terminated

I have an application which has communication with a remote server. The server should push data into it using remote notification silently, and I need to get and store these data into a CoreData database. The user won't be aware of the whole process.
I can successfully get notified when the app receives a remote notification, while it is either in the foreground or background mode. However, I need to get data while the app is terminated as well.
I searched for the possible solutions. For example, this SO question was good if I don't tend to use silent notification. I also saw the PushKit capability, but I am not sure about the Apple Review result.
What is the possible solution?
If I want to use VoIP and PushKit to get notified when the app is terminated, would Apple reject my application?
If you’re not creating a VoIP app and you want your app to be in the App Store then the correct answer is: it is not possible. The only thing that can be done is adjusting your requirements in some way.
For instance you can send some notifications that will be visible for user in the Notification Center and wait until the user taps the notification or starts the app the usual way. Then the app will be able to do all the operations you need.
The delivery of push notifications is not guaranteed, so you should not rely on them to synchronise data.
For example, if multiple push notifications are sent while the device is offline, only the last notification is delivered when the device comes back online; the earlier notifications are lost.
When your app launches one of the first things it should do is check with your server for new data.

What is the best way to keep updated the info of an iOS App?

Since push notifications may not be delivered sometimes (you can lose a few of them), you can not run code after the iPhone is turned on to check if there is new information available from the server, and you can not run code if your iOS App is closed... What can you do if you want to be as more accurate as possible in for example a Chat App in iOS?
I mean, inform the user as faster as possible that he has new info available. Comparisons: WhatsApp is updated without any delay.
You can do background fetch if your App is in background. But if the App is closed and you miss a push, it's not going to be up to date until the next push arrives or user opens the App. The same with silent notifications. If the app is terminated by the user, you are not going to receive it. Is there any way to solve it? It must be because other Apps do it... If there is any "private and secret" API that they are using (I read about this answer when no one know how to do that)... Is there any way to apply to use it?
UPDATE:
I'm using push notifications. The goal is to fix when a push doesn't arrive. Example: User A send chat message to user B. User B doesn't have the App open. The system lose the push. User B is not going to receive the message until he open the App.
Push notifications seems to be your only way even if you do loose a few of them, which I don't know how you would since they are pushed to apples secure server... but what do I know. As long as the user turns on the push notifications you should be fine. They may be delayed due to apples way of handling them. Honestly push seems to be the future, having your app constantly every minute or two check for new messages is a huge battery water in conjunction with normal texting apps. Your app should provide the best live data but since apple restricts to push notifications when the app is off or not running just stick to push notifications and only push major events to the user. I believe you can set up a job scheduler using quartz or schedulator to setup your server to push notifications to your app.

Silent push notifications and iBeacons

I have developed a small iBeacon based application, when the application detects one of our iBeacons makes a call to a web service to obtain a data set and send a local notification to the user. All this is working correctly.
I have now raised the idea that these local notifications could vary over short time intervals, with new content. The problem is that if the user does not leave the region of the iBeacon and reenters, the application will not "wake up" and the user will not receive the new updated notification.
After asking for advice on how to tackle the problem, someone suggested using remote notifications. Reading about it I found the silent remote notifications, but I'm not sure if I can use them as I'm thinking.
My idea is this, when a notification is modified or created and is associated to a iBeacon on the server, sending a silent push notification to the application so that it "wakes" if not in foreground. Thus, when the application "wakes up", you can do ranging few seconds, and if any iBeacon near detect and send the new notification.
Is this possible and permissible? I can send all silent push notifications that I want or is there some limit?Thanks
This is possible and permissible. You can read more about this in the Using Push Notifications to Initiate a Download section here:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
However, there are a few drawbacks:
Remote notifications can be slow to arrive, and are actually not even guaranteed by Apple to arrive at all.
They are a bit of a headache to set up given that you need to build server ifrastructure to send them.
A less timely alternative is to just do periodic refreshes, but the OS typically lets your app do this only once a day. See Fetching Small Amounts of Content Opportunistically here:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Push Notification : what is the condition to be count as a "spamming"

I'm implementing server-to-client communication in my iOS Application. What I'm trying to do is to deliver new messages from server to client such as
Old version will be no longer support soon, please update asap.
There is a new content available.
Reminder of some interesting content.
etc.
When device got message, it will notify user by showing "You got new X messages" with badge number. After user launch the app by clicking at the notification message, it will show those message containing images and text within my application.
At the beginning, I did this by iOS 7 background data fetch because the message content size that I mentioned will contains image url and text, it may exceed the maximum size of push notification content length. After testing with that approach, I found that there is no guarantee of when the application will be wake to connect and fetch new message from my server. (I left the device overnight to see how many time it connect to my server, first night was 5 times, second night was once)
Since some of the message is time sensitive (like reminder), I came up with the another approach by sending a Push Notification to the device when there is any new message to signal the app instead. But, according to App Store Review Guideline
5. Push Notifications
5.6 Apps cannot use Push Notifications to send advertising,
promotions, or direct marketing of any kind
5.8 Apps that excessively use the network capacity or bandwidth
of the APN service or unduly burden a device with Push Notifications
will be rejected
So, my questions are,
If I send a message contains promotions or marketing material but it won't showing at the iOS Device home screen, instead, user has to launch my application to see those contents, will it be the case of 5.6?
From 5.8, "excessively use the network capacity or bandwidth", do you know how many notifications can be sent to how many devices per time period? If I send 2 notifications to thousands of devices every hour, will that be the case?
Thank you, in advance.
5.6 wont be a problem, because i developed few which is working as like your scenario and they are live in app store.
5.8 also wont be problem i think, because i saw few application using push notification for voice call and video call application for intimate new call arrival for the user.
Some chatting application also using APN for intimation the user when
new message arrived for that user.

APNS (Apple Push Notification Service) reliability

Our app uses APNS to receive Push Notifications. However, our client claims that some of their devices were not receiving notifications and argues to they 'must' make sure the notifications to be delivered 100%. But I have read somewhere that APNS is not 100% reliable and there should be cases which the notifications are not delivered.
I'm currently panic at how we could make sure APNS to received anytime. I have read that a case which may APNS not delivered (device may offline). But our test showing that even the device is online (Wifi or 3G), sometimes APNS were not delivered.
Is there any specific case which may APNS will not delivered? Or is there anything we (developers) can do with codes to make sure to receive all notifications? What I have done in the code is just registering the app to remote notification and write didRegisterForRemoteNotificationsWithDeviceToken, then throw the device token to our server.
Any help would be appreciated, for our client almost kill us if ALL of their devices not receiving APNS!
APNS is based on Apple Servers, and Apple doesn't give any guarantee on successful message delivery.
If the app is open (i.e. the user is using the app) while the notification arrives, iOS doesn't show a notification message, you need to handle it.
Notification shows up only when the app is backgrounded or killed.
Also implement feedback service on your server side; will help you get rid of old unwanted tokens (users who deleted the app or disabled notifications through settings).
Don't send too many notifications to a device within a short span of time, because APNS caches only 1 message/device (if the device is offline). So it can deliver the message when the device comes online. Am not sure how long the message is cached though.
Or just implement Pusher... http://pusher.com
We're facing the same problem. As everybody said, APNS is a best effort service so you can't be sure every notification will be delivered, but what you can do is to be sure of which ones have been received. This is what we're about to do. We register in our backend each notification que ship and the mobile app reports back each notification it receives. Then we set a maximum time of waiting for a notification to be received, if we don't receive the report back we try again.
I hope it might be helpful to someone (even 2 years later)
It says it quite clearly in the Apple Docs that it is not 100% gauranteed and nor should it be used as so. Its sent with "best effort".
As per Apple's guidelines, APNS is not 100% reliable service which means your app may not get push notifications from Apple servers due to some of the following reasons:
Device is offline
Your app is in the foreground state, you need to manage the push notification.
Note: Apple rejects apps which make compulsion to use notification services. (I have faced it in one of my App)
For more information, you can look into this answer
https://stackoverflow.com/a/25830955/3278326

Resources