using local notification data coming from web service - ios

I am new to IOS and wants to used Local Notification feature of iOS.
my problem is i do not know if i can go with local notification. in my case data will come from web service... it is like..no specific date. default time interval is 60 Sec. after 60 sec app has to call webservice which will return notification data..and after some validation i need to push to user.
and if user click on view details it will launch appand get data via webservice.
Is using localnotification will serve my purpose? or i have to go with other approach?
Please help.
Thanks in advanced.

I think this 60 second thing is you polling the server every 60 seconds to fetch new data, then if there is new data post a local notification?
This is kinda possible with iOS7 but not exactly every 60 seconds, sometimes not at all, But in general it is strongly frowned upon. Instead the webserver should send push notifications when new data is available, It saves the user battery life.
On iOS7 there are silent push notifications (just don't include the alert) that can ask the client to do the validation you mentioned, and If the user needs a notification you can create a Local Notification to alert the user in a change
You should give this documentation a long look, it isn't trivial work for a new iOS programmer:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html
And here is a relevant Apple documentation quote "Local and push notifications serve different design needs. A local notification is local to an application on an iPhone, iPad, or iPod touch. Push notifications—also known as remote notifications—arrive from outside a device. They originate on a remote server—the application’s provider—and are pushed to applications on devices (via the Apple Push Notification service) when there are messages to see or data to download."

If you are trying to achieve this functionality to happen automatically/polling (i.e without user interaction like, clicking on the view details button)- the answer is a big NO at least not till iOS6.x
Your application cannot run for infinite length in background at-not till ios6.x. You may have to consider using APNS service to achieve this.
Otherwise, your approach on scheduling a local notification for ever 60 sec - The user clicks in the view option - the application comes up - You make a web-service call - Get the data - Validate the received data - Uploading to the server, looks fine to happen.
Will it not be annoying to the user getting notification for ever 60 sec & operating on the app to do whatever you intended to do? - Just curious.

Related

how to call a web service daily on particular time using local notification in objective c

My requirement is, I need to call a Web-Service and the count of the data should come on the local notification content on daily at 8 AM
example : you have 10 new notification, the 10 is the count of the data in an array.
Some one please help me to do this.
Thanks in advance.
you cant schedule something like this offline but you have 2 options that differ
with thr app background refresh API you may come close. If you opt in to that api, ios will wakeup your app when it has spare cycles and will give you cpu time to run some code and allow you to do this.
the background refresh api was meant for 'periodic' updates like this IMO. What you cannot do with it though, is schedule any EXACT times/dates/intervals you want to be woken. You can recommend times to ios but it may or may not stick to the plan (this depends on device use .... battery .... time of day...... etc)
another option are a backend that sends 'silent' push notifications at your required time. IOS would wake your app for those notifications and as they are silent, the user wont see it.
you can have a backend send you non silent pushes. Your app will be launched on tapping the notification and you can do whatever you like
==> option 1 works offline, option 2 and 3 require connectivity and even worse a decdicated backend to support it. IMHO option 1 is often very good and underrated.

Auto Refresh JSON

So my app extracts JSON from a server that i don't control, and parses that JSON to populate a UITableView.
I want to update my UITableView to reflect the latest information available on the server in real time. So Whenever something changes on the server my UITableView also gets updated.
Now one solution that comes to mind is to Continuously send GET Requests lets say after one minute, parse the JSON and reload data on the table.
However there must be some other solution for this problem. I have tried searching but thus far no success.
Now i understand this questions is somewhat subjective by stackoverflow's standards but really i need help regarding this matter and i haven't got the slightest clue on where to start. So any help would be greatly appreciated.
Repeated GETs are generally frowned upon, because it demands client and server resources when nothing is happening, which can be most of the time.
Since you don't control the server, I'd recommend building a server that you do control that can perform the polling, and then send the push upon detecting a change. This has a couple advantages over polling from the client: It scales better since only one source of polling will exist in the world, and it conserves client energy as well as the pure push approach does.
Apple provides a push system (APNS) wherein your server sends a message to your iOS device (via Apple). The device will launch your app in the background and invoke:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
on your app delegate.
As the above answer states, its better to use APNS.
if however, you truly do not control the server, then as you describe theres nothing you can do except poll. Since you're writing for iOS, you're well advised to consider a few things:
Wifi constraints: Are you fetching a tiny payload such that it doesn't matter whether you are on wifi? otherwise you ought to configure reachability to not be a drag on the users cellular service.
Backgrounding Sessions & background Execution: Consider using an NSBackgroundUrlSession to request this data. Backgrounding sessions are a bit more efficient to the OS in that they allow the OS to perform the request opportunistically. Consider The Background Execution entitlement if You need to customize the NSURLSessionTasks for the background session.
Scalability: can your backend handle continuous requests from your volume of users?
better solutions might utilize APNS, or Socket / WebSockets / Socket.io / firebase / etc.
Normal Silent Notification is best solution for this
When you adding any new item on server that time you can send push notification (Silent push notification) to devices to notify status that you added something on server side.
When device receives such push notifications then you have to call API and reload your table view. So you don't have to reload tableview every 10 sec.
It "will not show notification alert in notification bar, but it will only notify your app that there is some new data available, when you want to push new content.
Displayed in Notification center : No
Awake app to perform background task : Yes
just add below paylod from server side in push notification
{
"content-available" : 1
}
{
"content-available" : 1
}

Real time notifications on iOS

I am developing an iOS app which needs to receive regular data from the server at specific period of time (every 5 seconds).
Apple gives developers some choices for background working.
I convinced that Background Fetch is the proper method for my problem.
But when I tested it I got confused.
Background Fetch has many issues with my requirements:
It does not fetch data at period you defined when declared it:
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
I tried this and this:
application.setMinimumBackgroundFetchInterval(5). But no guarantee
that your app will fetch data at this interval.
When the screen is off, your app will not make any fetch until the
phone is unlocked again.
I wonder if there is a way that let my app receives real time data (or at least every 5 seconds).
Note: I read about remote notifications and I do not guarantee that I can execute it now, So I am searching for other solutions.
Thanks
There is no solution to this problem until writing this answer.
If I need a real time notification then I must use Push Notification.
There is no way to check for server data every period of time from the app only, I can send a Remote Notification when new data available on server to wake up the app and let it connect to the server.

iOS push notification and avoiding server overload

My app receives push notification about new data on my server. If user is interested, app downloads new data and displays it.
Imagine app is used by 100 000 users, and everybody receives that push in "the same time" and try to download new data from server - this might cause server overload problem, so I'm thinking how to avoid that?
I thought about making this like that:
- app receives push
- app sets timer with random time (maybe between 1 min - 5min)
- app shows notification after this random time
This way should be lighter for server.
Any other ideas?
Thanks

Get messages from server in real-time

It's generally a common question.
I wonder how do mail apps implement functionality of email-receiving?
I need to implement a simple sync between two devices(for example) using my web service.
Imagine a to do list app.
Is it possible to implement such a functionality: device1 makes an entry,then sends a message to webservice, webservice informs device2 that changes took place and device2 adjusts its data and displays that entry?
On iOS what you want could easily be implement with push notifications.
As soon as the server detects changes that device2 needs to be aware of the server will send a push notification to that device.
After the user views the notification the app should update it self, it would also be a good idea to let the app update it self when coming to the foreground.
The reason for doing it with Push Notification and not polling is that if your app is in the background you can only continue to run a process for 10 min max. You might get around this by adding the background mode to your app, like VOIP, Audio or location. But if you app does not fall in those categories apple might reject your app.
With Push notification the device will receive the notification even if your app isn't running or in background.
Basically there are 2 ways:
polling, each device asks the webserver for changes every N minutes: new todo, delete a todo, change a todo, ... and then each device will adjust. The frequency of the poll depends of the level of real time you are looking for. It can be 1 call every second or every 12 hours or much more.
implement a kind of BOSH protocol: the device opens a connection to the server. The server keeps it open until there something new to send to the device or the connection times out. In that case, the device reopens it.
Option 1 is better for your todo app because you don't need real-time accuracy. The option 2 is better for a chat application where you don't want to wait for the message.

Resources