skip one notification, repeating each day - ios

I'm making an app, reminding user to do smth each day, and I can't implement the situation , when notifications are shown or not shown depending on some condition even if the app is in background mode.
one possible variant is to set endless repeating notifications:
notification.repeatInterval = NSCalendarUnit.NSDayCalendarUnit
but then some method is required to skip notification for present day if some condition was satisfied. If one removes these notifications from Notification Center they won't fire next day.
The other way is to make some method creating notification only for present day, and then removing them if some condition is satisfied. The problem is, this method should create these scheduled notification even being in background mode, and I have no idea how to make that.
Are there any ideas?

Unfortunately the only way you can wake up your app at a specific time is through a silent APNS push. This means you need a server that will send silent pushes to your device, the user needs to have internet and the user needs to opt out for push.
Maybe background fetch will work for you ? With Background Fetch your app gets woken up every minimum interval. You could set your app to wake up every x minutes and check that condition.
[application setMinimumBackgroundFetchInterval:100]; //seconds
Please beware that:
The minimum number of seconds that must elapse before another
background fetch can be initiated. This value is advisory only and
does not indicate the exact amount of time expected between fetch
operations.

Related

local notification at different times everyday

I would like to know what is the best approach to do if I want to fire notifications for more than one time each day everyday.
I did some research and read that notifications for the next day cannot be fired unless the user opens the app the next day and updated the notification. Is that true? is there anyway I can do it without the need of the user opening the app everyday?
Thank you
You can schedule up to 64 local notifications. There is no limit on the time period; you can schedule them years in advance if you like.
That said, if you need some mechanism to schedule new notifications, even if the app is not running at all (e.g. because the user terminated it), you need a background mode for that. Fetch is probably the way to go here, as it doesn't need a special trigger. You could also send silent push notifications in order to wake the app, make the calculations and schedule the new notifications.

iBeacons and local notifications

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.
I do not know if this could be solved somehow or actually the approach to make something like that should not be related to technology of iBeacons.
I'm really lost and do not know if anyone would know advise me on how to raise it.
You can schedule local notifications to be delivered at a specific time: use the fireDate and timeZone properties of the UILocalNotification, and then use scheduleLocalNotification instead of the presentLocalNotificationNow method of the UIApplication.
With that in mind you could do this: upon an "enter" event, retrieve a few notifications to be showed to the user over a certain time period while they remain in the zone, schedule them appropriately and let iOS do the delivering.
If the user exits the zone before all the notifications are shown, you can cancel the remaining local notifications using cancelLocalNotification or cancelAllLocalNotifications methods.
In order to do this, you need to get the app to run in the background while beacons are in the vicinity. This would allow you to periodically check for updated content associated with the beacon and then display notifications under two conditions:
When a beacon first appears, and there is a message associated with that beacon.
The message associated with the beacon above changes during the time the beacon is still visible.
As you mention, the second item is a problem, because you need a way to continually check to see if there is updated content despite the fact that iOS will suspend your app within 5 seconds of beacon detection in the background.
A few options, each of which have downsides:
You can use a custom hardware beacon that changes its identifier every minutes or so (e.g. the minor goes back and forth between 0 and 1). This would allow you to monitor two regions and re-trigger on each every minute the beacon is in the vicinity. Downside: This requires building a custom beacon.
You can make your app request an extra 3 minutes of background running time during which you can check for changed messages. Downside: You only get three minutes to display changed messages.
You can specify extra background modes in your .plist so you can continue running in the background. Downside: Apple won't approve your app for distribution in the store unless you have a good reason to run in the background (e.g. a navigation app or a music player app.)
You can send a push notification to your app each time the message changes, which would wake up your app in the background so you could display an updated notification if a beacon is in the vicinity. Downside: Setting up push notifications are a bit complex, delivery can be slow, and is not guaranteed.
Read here for more info on some of these options: http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html

What is the best way to modify a UILocalNotification after it has fired?

I understand that you cannot modify a UILocalNotification after it has been scheduled. My problem is that I want to set the .repeatInterval so that it fires at a specific time once per day. However I want the content to change every day. So the user sets the alarm to fire at 10AM, and every day at 10AM gets an alert with different content without having to reset their alarm.
I was thinking about canceling and rescheduling when didReceiveLocalNotification was called but that requires the user to launch the app before the next scheduled alert. Is there a way to call a method immediately after the alert is fired?
Unfortunately you have no certain way of knowing that a local notification has fired unless your app is frontmost at the time it fires.
And, as you say, you cannot change a notification.
So I think your best bet is do not use repeating notifications. Set up a different single notification for each day, say, two weeks ahead, with different messages for each, and hope the user runs the app between now and then so that you can "refresh" the queue, as it were. Maybe make only the last one repeating, just in case, so that the notifications never stop - but of course then the message will be same each time. But there's nothing you can do about that. You can't force the user to run the app.

Schedule iOS Push Notification with Parse.com

I am trying to schedule push notifications using Parse in iOS. I only have a free account (meaning that I cannot schedule notifications in the web backend), so I came up with a solution for scheduling the notification through Parse:
Within the app, when you press send notification you set the text and a date to send the notification (using the code to just send a standard PFPush code). Then I just use NSDate and every day check the date to see if it matches the date for the scheduled notification. If it does, it sends the notification; thus sending the notification on the scheduled day, if it is not the matching day, nothing happens (no notification is sent, and the app rechecks in another 24hrs). This works, but the app has to be open in the foreground at the time that the notification is scheduled for sending (i.e the date is not checked and notification not sent if the app is in the background). So my actual question is how I can run all of this in the background, so the app can just be in the background on my iPad, and it will still check the date and be able to post the PFPush (push notification).
Any help or code would be much appreciated.
Thanks so much in advance, and let me know if you need more information!
In this case
setMinimumBackgroundFetchInterval means that it is not called in an interval which is smaller than the value you specified. But there's no setMaximumBackgroundFetchInterval. So if iOS decides to call your app just once a day or even just once a week than it won't be called more often regardless your minimumBackgroundFetchInterval. AFAIK iOS decides when to call performFetchWithCompletionHandler measured by the pattern when and how often the users start's the app.
In Xcode 5 Debug mode, you can force a background fetch from the menu: Debug > Simulate Background Fetch.

Schedule next UILocalNotification if app is not running

I am working on an app for a trash company. The idea is as follow:
There is a calendar for 2012/2013 with dates when and what trash can (brown, gree and black) will be picked up.
I need to make a kind of notification system which will send a notification on a specific day (from that array) with some text about what container will be picked up this week.
That would not be smart to post all notifications at once coz there are over 100 (and I've heard the limit is 64 in iOS).
I thought to schedule next notification after the current one fires. This could be done in the kind of handleNotification method when user touches the action-button at the notification and goes to the app. But what if the user gets enough information from the notification window and never touches that notification, never goes to the app and mostly have it in the "non running" state at all?
How to schedule next notification then?
Maybe some smart heads can come with other ways to make it works without using UILocalNotification?
There is no way.
If the user never opens up your app you will at most have 64 scheduled notifications. When all those have been triggered there will be no more notifications.
Although you can have your notifications repeating. So if the brown trash can will be picked up every week you can set a repat interval of weekly instead of scheduling it 52 times (thus saving 51 notifications).

Resources