Silent notification - ios - ios

I'm building an app and I have created a method to detect if the user has new pictures in his photo librery throw ALAssetsLibrary, the method works fine.
I want to run this method from time to time to check for new pictures. If the user has new pictures, to notify him by a notificaiton.
I'm searching for a trigger to activate this method from time to time while the app is in background state or not running at all.
I know by sending a silent notification in ios 7, I can activate the app on the background state.
Once a silent notification is received , can I activate the method somehow? or the silent notoficaiton is just for receiving data and update the app.
Do you think of any other way that I can activate this function without the user will know about it ?

Not Possible currently!
1- When a silent notification is received the app is only intended to upload/download data hence we can only work with NSURLSessionTask. Access to other API's which require asynchronous blocks to execute like ALAssetLibrary is not available.
2- No other option of scanning library without the user knowing. You can display a notification to User and then on User's discretion app can be launched to perform desired scanning.

Related

Can notification actions be handled while the device is locked?

I've been working with notifications for quite a while now, and I could've sworn that userNotificationCenter(_:didReceive:withCompletionHandler:) used to only be processed if the app was opened via the notification.
However, upon looking into actionable notifications, I found this:
When the user selects an action, the system launches your app in the background and notifies the shared UNUserNotificationCenter object, which notifies its delegate. Use your delegate object's userNotificationCenter(_:didReceive:withCompletionHandler:) method to identify the selected action and provide an appropriate response.
Does this mean that the seemingly universal didReceive delegate method now works even while the device is locked?
Or must the app always be opened to actually do anything meaningful in response to notification actions (writing to local database, sending HTTPS requests, etc.)?
Yes, the delegate works even if the device is locked. The app is only woken up if the user chose an action. Also, I am not sure how much time you will get before you invoke the completion block.
Important
If your response to action involves accessing files on disk,
consider a different approach. Users can respond to actions while the
device is locked, which would make files encrypted with the complete
option unavailable to your app. If that happens, you may need to save
changes temporarily and integrate them into your app's data structures
later.
From this Delegate Method : userNotificationCenter(_:didReceive:withCompletionHandler:) notification is works when your device is locked, but if you want to perform any action.
For Example: Suppose through Notification you want to pick any phone call within application then you have to setup another things as well.
you have to set up PushKit Framework within your application . As shown in images:

Fetching local notifications in iOS and display in the app

I am implementing a feature where in we will be scheduling local notifications. So far, I have followed all the document and seems to work fine i.e
if the app is in the background / foreground i do get the notifications.
however, I also need to display all the notifications that have occurred inside alerts section of the app after it comes to the foreground, so that in case the user had snoozed / closed the alerts, he could take actions on the notification when listed in the alerts.
Is there a way I could fetch all the notifications that were fired when the app was in the background ?
Not from the application, it can only tell you about future (or future repeating) notifications.
You should keep a record of the notifications that you are scheduling and which have been triggered (used to open the app or received while in the foreground) so you can display an appropriate list.

how to start my App in a particular time of the Day in Swift iOS

I have an App built on Swift, I want this App to start every day at some particular time. Logically its like Calendar notification, which gives notification in that particular window whatever we set.
Does is the same scenario is possible with an App in iOS Swift.
What you can probably do is to create a local notification, but this is not opening your app. A local notification is just a way to show a notification on your iPhone and then, if the user taps, it's opening your app.
See more here: https://www.codebeaulieu.com/49/How-to-add-local-notifications-to-your-app
I am not sure what you want to do, you cannot force your application upon the user without the user's consent. What you can do is schedule a local notification so the user knows when to open your app like jomafer proposed already. Also possible is to wake up the app to do stuff in the background:
https://developer.apple.com/library/prerelease/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
For example a silent push notification that will trigger some code, or a scheduled background download.
NONE OF THESE METHODS ARE 100% RELIABLE THOUGH!

How can i store iOS remote notification when app in state background or killed, and without tap the notification?

I want to save all the notifications from server.Is that only way is to request server to get all messages?
You may use silent notification feature which lets your app do simple operations (e.g. purchase sync or file sync) without bothering the user or having the user open the app.

iOS7 Local Notification for app polling server for new data of interest running in the background

I'm just wondering if using Local Notification is possible for my app instead of Push Notification.
My app get data from my sever via the server's API. It's a small social network for soccer player. I'd like the app to notify the user when the user's friends post a pickup game in the user's city.
Is it possible for the app to run a background process to poll the server for new pickup game in the city say every 10-15 minute, when there is a new pickup game, it sends a notification to the device?
What you want to do is implement the iOS7 background multi-tasking API and perform background fetches. Decent tutorial here: http://hayageek.com/ios-background-fetch/
You don't have control over when the operating system allows you to wake up in the background to perform the fetch, but during this operation you could poll your server and if new data was present use that to show a local notification.
It is not possible in the way that you're thinking. When a local notification is fired, you cannot execute any custom code unless (or until) your app is actually active. If the user does indeed tap on your notification in notification center, you can get the notification info from your application delegate from either the launch options in application:didFinishLaunchingWithOptions: if your app is starting up or from application:didReceiveLocalNotification: if your app was already running but in the background.
If you're okay with this only working while the app is actually in the foreground, then you can set whatever timers or notifications you want.

Resources