Question

We are creating an app which reminds a user about certain tasks. The user can choose to recieve the reminder on the following bases:

One Time, Daily, Weekly, Weekly (on a specific week day), Every Two weeks, Once a Month

The reminders should be a custom popup in the app and/or a popup if the application is closed. My question is, what is the best way to go about setting up reminders like these?

The way I'm thinking about doing it is to load it into the phone's SQLite database and then checking for reminders each time the app starts up, and if a reminder is, let's say a daily one, the app would automatically set the next reminder. I have no idea how I'm going to do the rest yet.

Thanks

Was it helpful?

Solution

I do this in my app by using NSLocalNotification

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
    return;
localNotification.fireDate = dateToRemindOn;
localNotification.timeZone = [NSTimeZone defaultTimeZone];

// details
localNotification.alertBody = @"Alert Message";
// Set the button title
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName;

// custom data for the notification to use later
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:reminderID forKey:@"remindID"];
localNotification.userInfo = infoDict;

// Schedule notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

This will create the local notification and you can store any information you might need in the user info dictionary and that will be available to you when it is received or opened.

Use this method in your AppDelegate to check if the app was opened from your local notification.

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

    // Handle launching from a notification
    UILocalNotification *localNotification =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotification) {
        //handle local notification
    }
}

And use this method in your App Delegate to catch when a local notification is received while the app is open

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle notification when app is running
}

OTHER TIPS

You can setup a NSLocalNotification and handle the application states : when you are inside the app you can push your custom view, when you are outside the app you'll receive the standard alert.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top