We are planning to have end to end encryption in our messaging app, so cannot display user message as the APNS push notification message directly. So we are planning to send a silent Push notification, decrypt the message in the iOS App's background mode and then display the plain text message as a local notification
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
Yes, you could event just send the silent notification (using the contentAvailable flag in the payload) but only use the notification to notify your app of a message availability, in which the delegate method then downloads the message from a database on your secure servers then pushes the local notification to the device like you are saying.
That way you aren't even giving apple the opportunity to decrypt your message because it won't even go through their servers.
Related
right now I'm developing an app capable of receiving notifications, and it was going fine, until I stepped on the need of having to send to my server a copy of the notification received on the app.
Although I know the downsides to this approach, it's the only way that I can process the notifications received.
Right now I can handle the notifications that are received with the app on background and foreground through this method
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
. Inside this method I call the NSURLConnection sendAsynchronousRequest to send to my server the notification data received.
But when the app is killed (eliminated from the the background apps), I no longer can process the notification through this method.
Is there a method that I can call when the app is killed that allows me to make a post request to my server after I receive the notification?
I think there is no way to do this until and unless you open the App...
Can we have a silent local notification in IOS app. Which does some data processing in the background with out the user interacting with it.
What I want to do is create a silent local notification which fires every 8 am in morning and after the user receives it I want to do some data processing and recreate a new one which the user can see with the new data I processed after I saw the first silent local notification.
I am trying to avoid using push notification as much as I can.
You can receive silent notifications in the background on iOS, but you will need a server to actually send the notifications.
To do this you enable the Remote notifications background mode in your target's Capabilities tab:
Then you register for push notifications in application:didFinishLaunchingWithOptions: with
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeNone categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
Pending the user allowing your app to send push notifications, you will receive the device token:
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
If something goes wrong, the failure handler will be called:
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:
You send the deviceToken to your server and tell it to send a silent push notification to that deviceToken at the device's local time of 8AM.
That device will have the following app delegate method called:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;
and you will be able to do your data processing.
Easy!
Don't forget to call the completion handler when you're done!
i have a question. I have configured my app for development push notifications and all was working fine.
All push notifications arrived the app on the device. But i want to handle the push notification in a special way. If my app is running or in background the function
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
will work fine. But is the app killed the function doesn't work. I need a idea to handle incomming push notifications whether if the app is running, in background or killed. If a push was received the app must call a callback URL. if there any way to realize this?
for example i send the following apn string:
{"aps":{"content-available":1,"alert":"This","badge":1},"callback":"https://www.xxxxxxxxx.com/sf/daniel_push/985270815/12323453534534/?device(id)=1111111111&s="}
At the end all what i want is to call the callback url if the app becomes a push notification.
Try this in didFinishLaunching:
NSDictionary *userData = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userData) {
// handle notification
}
I am working on a app, where I need to send a push notification to the app to start processing data as needed.
How do I send a push notification to the device so that instead of showing the alert message, the notification is forwarded to the app - whether the app is in the foreground or background..
I did implement the delegate method :
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
however this is called only when the app is in the foreground. When the app is in the background the notification shows up on the notification center.
Please advice.
To make this works you need to do few step:
set background mode remote-notification
implement application:didReceiveRemoteNotification:fetchCompletionHandler: method in app delegate
and make sure push notification payload contains key "content-available" : 1
related docs:
App States and Multitasking
Local and Push Notifications in Depth
Is your application using a backend? An example would be Parse or another to store your data.
Parse, for example, allows you to add push notifications that can be customized and changed to get the most out of your application.
I would like to know, if the user click the notification in the notification centre, whether the application can detect which notification they are clicking and how I can handle it? Thanks.
Yes. In your app delegate, the notification details will be received in the method - (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
The userInfo will have the payload that you sent with your push notification. It recommended that when you send a push notification that you include identifying information in the payload (such as an object id) to figure out which push notification was selected/received.