This is a sample iOS application to monitor directory changes in the background.
The video depicts adding/removing files using iTunes File sharing feature. iPhone is running iOS10.
Here's a short preview if you can't open YouTube for some reason:
- Background execution is achieved by requesting 'Always' location updates.
- File changes are tracked with GCD descriptor dispatch source.
- Notifications are reported using local notifications.
There are a few things that can be improved. However, since this is only a sample, they are left out.
-
Waiting for changes to finish. There are several use cases where reporting right away does not make much sense
- When several files are added or removed, there is a notification for each one of them
- When a large file is added, notification is reported before the file has been uploaded
-
Supporting UNUserNotificationCenter
- UILocalNotification is deprecated in iOS10, but still works
NotificationWithLNAndUNC
directory contains an attempt to use UNC if it's supported, but since the async nature ofUNUserNotificationCenter getNotificationSettingsWithCompletionHandler:
ruins the pretty interface ofNotification
class, I decided to stay with UILocalNotification
Here are some of the docs I used to implement the sample.
- Directory monitoring with GCD
- iOS background execution