Objective-C IOS 7 push notification keeps data when app is down?

I have created an ios app with push notifications setting, everyone can communicate with others in my app and I will solve some problems:

1) Solved: When the app is not active but still running in the background (don't delete everything), I can handle the push notification and save the code to the database (SQLite):

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    //some code here
}

      

2) Solved: When the user has finished logging out of my app, a new message is logged in and the user clicks on the notification ball and the user can read the new message, for that I will use this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    /* this code working when application not running */
    NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
    if(remoteNotif)
    {
        [self handleRemoteNotification:application userInfo:remoteNotif];
        return YES;
    }
    return YES;
}

      

3 Not resolved and my problem needs help

  • When the user has finished logging out of my application, a new message logging in but the user does not touch the notification bar, the user application is closed by touching the application icon on the iphone screen, and this action I cannot get any data to show in the application.

Please, help

+3


source to share


2 answers


If your app is not running and the user clicks on a push notification to open it, you can get the details of that notification in a method application:didFinishLaunchingWithOptions

.

According to Apple Documentation :

If your app is not in front or is down, you handle notifications by checking the options dictionary passed to application: didFinishLaunchingWithOptions: of your app delegate for UIApplicationLaunchOptionsLocalNotificationKey or UIApplicationLaunchOptionsRemoteNotificationKey .



But if the app doesn't launch when a notification is received and the app doesn't open by tapping that notification, you wo n't receive your data.

This, together with the fact that push notifications are only the best effort (see note below), tells us that we should always have another method to get information (as Chetan said). Therefore, never rely on push alone .

Important: Delivery of notifications is a "best effort", not guaranteed. It is not intended to deliver data to your application, but only to notify the user when new data is available.

+2


source


To answer 3 bullets if they haven't been solved yet. In iOS 7.0 and later, you can send notifications and access your content without the user clicking on it. So the notification payload that you send has a content-available parameter . You can view the payload parmators at the following link: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

So when you set the available content to 1 and deliver the notification, iOS calls the function below even if the app is not in the background or foreground (there must be a remote notification)



- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

      

Then you can use the userInfo dictionary to retrieve your notification data.

0


source







All Articles