iOS Notification on battery level - ios

I'm developing an iOS app, and I'm looking for a way to make a notification appear when a specific battery level is reached. So my app has to do that while in background.
I found a tutorial with local notification, but the only way to make it appear is to set up a precise date and time.
If you have informations about it, it'll be very sweet.
Thanks for your help !

There is no easy solution for this. You have to run time to time your app in order to achieve this and check if desired battery charge level has reached then post an immediate notification if it's the case.
As a working case you can use background fetch mode to wake app at specific time intervals and do the required battery level check. Be aware that background fetch doesn't provide a consistent time period, you can't wake up app each 15 minutes or 30 minutes, the time is calculated by the system and it's variable, this can make app to "miss" the target level.
You can use also, silent remote notifications which wake your app when delivered, you do the check and present the local notification if needed. This is more reliable than the first case but of course you need to setup a push notification server or use a service which implements this.
Honestly being you won't find a 100% reliable way to do this, so if this is a primary feature of your app think twice before implementing it.

You can check battery Level in back ground. When it will reach specific level as per your requirement immediately fire Local Notification.

Related

Some app fires alarms more then 64(local notification) , any way to manage this?

In my app i need to update locally settled alarms with local notifications, after 64 has been fired then set new 64 is remaining even though app is killed by user.
This means it needs to update alarms while app is killed.
In iOS that is not allowed, but
Some applications like Alarmy, Alarm Clock Pro, dozen are doing some what like this.
So is there any way to get this?
Any help will be appreciated
Thanks
I've encountered the same problem. What I've done was to create a queue and on every launch of application I rescheduled notifications based on the queue. 64 can be scheduled and the others are in the queue according to their fire date. I've also created silent push notifications that would arrive every n hour in order to force my app become active. With this approach, I could take care of that queue even if the user doesn't open the app. Your goal can be achieved but it is really difficult to implement.
After all, iOS ecosystem does not let third-party apps that have the same functionality as OS 's default apps to thrive. So basically if you're creating an alarm app you should better think again.

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.

In iOS, is it possible to start region based geofencing at a particular time?

My iOS app (which targets iOS 8.1+) use location services to determine if a user has entered a particular region during an event. Ideally I would like to enable the geofencing a little before the event and turn it off a little after the event completes. The problem is there is no guarantee the app is running an hour before the event so I turn on geofencing at the point the user registers for the event. This is not the best approach as it means the geofencing is on for much longer than it needs to be.
As far as I can tell, there is no way to "wake up" the app in the background at a scheduled time in iOS. I could use the push notification meant for updating content, but It's not clear to me if Apple would reject such a misuse of that notification.
Any suggestions?
I've been looking into this myself.
If you can arrange a push notification from your backend ("Silent push notification", aka "content-available"), it seems to be a good option. In real-world situations, this seems to give you the best control over the timing. Unfortunately, it won't work if the person doesn't have connectivity. Also, unfortunately, you need a backend that can queue events at a time (not just in response to an input.) If you have such a backend already, and your app is only useful to the user when they have network coverage anyway, this is probably the best option. It seems this an appropriate use of the technology, so Apple should approve.
Another option I'm trying is to use background fetch. You specify a "minimum interval" to avoid too much fetching. Try 50% of the remaining time-to-event as a minimum. Every time the app wakes up (whether in the foreground because the user opened it, or in the background because background-fetch opens it) you can calculate the time-to-next-event, update the fetch interval, or start the region monitoring. You are supposed to use "background fetch" to fetch information from a server, but there doesn't seem to be any requirement to poll a server, you could poll your internal data instead. I haven't fully tested this yet but it seems promising.
You can use significant location change monitoring, which I've read will wake up your app briefly every 15 minutes or less, and you can use the time/location information to decide whether to turn on the geofence. I think this would work well in combination with the above "background fetch": Many hours or days before the event you rely on background fetch, which you then use to turn on significant location change monitoring a few hours before the event. (There's speculation that geofencing is actually more battery efficient than significant change monitoring, but you could choose to assume that other apps on the user's device will already by watching for significant changes, in which case the marginal cost of your app adding itself to the list should be minimal.)
Putting them all together, you could create a sequence of
background fetch -> significant location monitoring -> geofencing
as the time gets closer.
There is also the CLVisit monitoring functionality, it's not understood very well, but supposedly uses less power and is called less frequently than significant location change monitoring. If the background fetch or silent remote notifications aren't working to wake up your app, give this a try, and please report back!
You can't (yet) do a silent content-available local notification (AFAICT). However, perhaps you can schedule up a local notification "Your event starts tomorrow" or something that convinces the user to click the option that starts the geofence. Here's a tutorial on it http://www.appcoda.com/local-notifications-ios8/, the response of action can be UIUserNotificationActivationMode.Background so your geofence can come on (if the user responds to the notification) without bringing the app to the foreground.
It's been 5 to 6 weeks since you asked, do you have your own answer already? Please let me know.

iOS Background Fetch mode can be used to schedule some operation in the future that doesn't actually fetch remote data?

I'm doing an app that requires to reschedule local notification on daily basis. I'm aware about the repeatInterval property, but repetitioon here is like each 2 days etc.
I've seen silent notifications, but they can be used only with push notifications and due to some requirements I can't use that approach.
Now the app works on the hypothesis that the user will open the app quite enough to reschedule those notifications. This hypothesis is fine and we all agree that will work, but I will be more confident, if it would be possible to reschedule them on daily basis without opening the app.
I've seen the new API Background Fetch, this could be really good for me, but from doc and WWDC videos I didn't understand if it is possible to use for "everything" or just to fetch remote data.
As I understand you can do everything that does not take too long, plus you don't get a guaranteed interval when you app will be woken up - you just can request a certain minimum wake interval, which will be treated as a suggestion by iOS.
The only catch is that apparently you have to create an NSURLSession and actually do a web request, upon which return you can do whatever you want. So, you can do a dummy request and forget about any data you get returned, or maybe even create a failing request, as you are not interested in any real request at all - although I'm not sure what Apple will do when you implement the latter ...
You can use repeatInterval property of localNotification
localNotification.repeatInterval=NSWeekCalendarUnit;
For daily basis you can use NSDayCalendarUnit
No there are not API which can wake app after some time interval.
In back ground fetch mode application will wake up after you set minimum time. Application will wake up any time after minimum time interval might be after 5 min or 1 sec. and that will decide system on application usage. so we can not take this approach, if you willing to retrieve remote data compulsory after some time interval.this may help u.
http://www.doubleencore.com/2013/09/ios-7-background-fetch/

Can a background app (with a location UIBackgroundMode) use a timer to poll a server every few hours?

I have a background app with a UIBackgroundMode of location.
I would like my app to additionally contact a server every few or several hours to see if there is some new data for it (because using apple notification push would notify the user and that is not desirable).
Polling is something I would never use on any other OS, but with iOS they don't leave you much choice if there is certain functionality you would like to try to achieve.
If the polling interval is quite lengthy such as a few or several hours between polls, and the polling activity itself only lasts several seconds then the usual knee-jerk reaction about it draining battery life is greatly diminished.
Would a repeating NSTimer fire when an app is in background mode? If not is there another type of timer or mechanism available?
If it's just to check for new content, and not really time sensitive, you COULD use the significantChanges background location method...but if the user stayed fairly immobile it'd rarely/never fire. I would probably also add the update check in applicationWillEnterForeground to be more sure
No, that's not allowed. You should have a look at Push Notifications and find a server side solution.

Resources