Jak*_*sie 2 reminders schedule ios
我们正在创建一个应用程序,提醒用户某些任务.用户可以选择在以下基础上接收提醒:
一次,每日,每周,每周(在特定的工作日),每两周一次,每月一次
如果应用程序关闭,提醒应该是应用程序中的自定义弹出窗口和/或弹出窗口.我的问题是,设置这些提醒的最佳方法是什么?
我正在考虑这样做的方法是将其加载到手机的SQLite数据库中,然后在每次应用启动时检查提醒,如果提醒是,让我们说每天一个,应用程序会自动设置下一个提醒.我不知道我将如何休息呢.
谢谢
我在我的应用程序中使用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];
Run Code Online (Sandbox Code Playgroud)
这将创建本地通知,您可以将您可能需要的任何信息存储在用户信息词典中,并在收到或打开时提供给您.
在AppDelegate中使用此方法检查应用程序是否已从本地通知中打开.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Handle launching from a notification
UILocalNotification *localNotification =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
//handle local notification
}
}
Run Code Online (Sandbox Code Playgroud)
并在App Delegate中使用此方法,以便在应用程序打开时收到本地通知
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle notification when app is running
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1816 次 |
| 最近记录: |