2

我们正在创建一个提醒用户某些任务的应用程序。用户可以根据以下情况选择接收提醒:

一次、每天、每周、每周(在特定的工作日)、每两周、每月一次

提醒应该是应用程序中的自定义弹出窗口和/或应用程序关闭时的弹出窗口。我的问题是,设置此类提醒的最佳方法是什么?

我正在考虑这样做的方式是将其加载到手机的 SQLite 数据库中,然后在每次应用启动时检查提醒,如果有提醒,比如说每天提醒,应用会自动设置下一个提醒. 我不知道我将如何做剩下的。

谢谢

4

2 回答 2

5

我使用 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];

这将创建本地通知,您可以将可能需要的任何信息存储在用户信息字典中,并且在收到或打开时可供您使用。

在您的 AppDelegate 中使用此方法来检查应用程序是否已从您的本地通知中打开。

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

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

并在您的 App Delegate 中使用此方法来捕获在应用打开时收到本地通知的时间

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle notification when app is running
}
于 2013-07-15T08:00:35.347 回答
0

您可以设置NSLocalNotification和处理应用程序状态:当您在应用程序内时,您可以推送您的自定义视图,当您在应用程序外时,您将收到标准警报。

于 2013-07-15T07:40:19.733 回答