iOS闹钟实现
2016-02-17 10:24
615 查看
UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil)
{
NSDate *now=[NSDate new];
//notification.fireDate=[now addTimeInterval:period];
notification.fireDate = [now dateByAddingTimeInterval:period];
NSLog(@"%d",period);
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.soundName = @"ping.caf";
//notification.alertBody=@"TIME!";
notification.alertBody = [NSString stringWithFormat:@"@%时间到了!",nameStr];
NSDictionary* info = [NSDictionary dictionaryWithObject:uniqueCodeStr forKey:CODE];
notification.userInfo = info;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
设置的时间到了以后,会自动在桌面弹出一个提示框,点显示后,就可以启动软件。然后在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
NSLog(@"Recieved Notification %@",localNotif);
NSDictionary* infoDic = localNotif.userInfo;
NSLog(@"userInfo description=%@",[infoDic description]);
NSString* codeStr = [infoDic objectForKey:CODE];
}
}里,对lanchOptions进行处理,找到它里面的信息,就可以拿到设置时的需要处理的东西,就可以继续操作了。
如果此时你的客户端 软件仍在打开,则会调用
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
}
一样的处理方法。
if (notification!=nil)
{
NSDate *now=[NSDate new];
//notification.fireDate=[now addTimeInterval:period];
notification.fireDate = [now dateByAddingTimeInterval:period];
NSLog(@"%d",period);
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.soundName = @"ping.caf";
//notification.alertBody=@"TIME!";
notification.alertBody = [NSString stringWithFormat:@"@%时间到了!",nameStr];
NSDictionary* info = [NSDictionary dictionaryWithObject:uniqueCodeStr forKey:CODE];
notification.userInfo = info;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
设置的时间到了以后,会自动在桌面弹出一个提示框,点显示后,就可以启动软件。然后在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
NSLog(@"Recieved Notification %@",localNotif);
NSDictionary* infoDic = localNotif.userInfo;
NSLog(@"userInfo description=%@",[infoDic description]);
NSString* codeStr = [infoDic objectForKey:CODE];
}
}里,对lanchOptions进行处理,找到它里面的信息,就可以拿到设置时的需要处理的东西,就可以继续操作了。
如果此时你的客户端 软件仍在打开,则会调用
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
}
一样的处理方法。
相关文章推荐
- Missing iOS Distribution signing identity for XXXXXX问题
- IOS NSInvocation应用与理解
- iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)
- iOS Provisioning Profile(Certificate)与Code Signing详解
- iOS: 复选框使用---第三方框架SSCheckBoxView-master
- iOS 开发之动画篇 - Transform和KeyFrame动画
- iOS 集合NSSet 用法详解
- ios开发--证书显示 此证书签发者无效 解决办法
- 超全!整理常用的iOS第三方资源
- 超全!整理常用的iOS第三方资源
- iOS开发证书显示“此证书的签发者无效”解决方法(相对完整版)/Missing iOS Distribution signing identity
- IOS开发常用函数
- Cisco 交换机IOS升级
- iOS开发之版本控制(SVN)
- iOS开源现成的有用的东西,方便以后找
- 腾讯移动游戏平台SDK(MSDK) ios版Ane扩展 过程中所遇到的问题
- ios开发 解决用lame转换成MP3时,播放时间变短的问题
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS 解决block中self的循环引用问题
- Windows下搭建IOS开发环境(三)- 安装Vmware tools