UILocalNotification 本地通知的应用实例
来源:互联网 发布:java时间字符串转整形 编辑:程序博客网 时间:2024/05/18 22:52
1.单机按钮触发这个本地通知
- (IBAction)sendnotificationClick:(id)sender {
UILocalNotification *notification = [[UILocalNotificationalloc]init];//初始化一个本地通知
if (notification!=nil) {
NSDate *theTime = [[NSDatealloc]init];//实例一个时间对象
notification.fireDate = [theTimedateByAddingTimeInterval:5];//5秒后执行这个通知
notification.timeZone = [NSTimeZonedefaultTimeZone];//设置时区
notification.soundName =UILocalNotificationDefaultSoundName; //设置提示音
notification.alertAction =@"确定";//提示框按钮;
notification.applicationIconBadgeNumber=1;//设置App有上角的数字;
//发送通知
[[UIApplicationsharedApplication]scheduleLocalNotification:notification];
//下面设置本地通知发送的消息,这个消息可以接受
// NSDictionary* infoDic = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
// notification.userInfo = infoDic;
//这我没有做操作所以就注掉啦!
}
}
以上本地通知就设置好啦,但是发送这个通知我要干什么,,什么事都是有因有果的,所以接下来 就是处理他的结果
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"将要进入后台");
application.applicationIconBadgeNumber -=1;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification{
//设置这个提示框
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"消息"message:notification.alertBodydelegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alertshow];
// NSDictionary* dic = [[NSDictionary alloc]init];
//这里可以接受到本地通知中心发送的消息
// dic = notification.userInfo;
// NSLog(@"user info = %@",[dic objectForKey:@"key"]);
// NSDictionary* dic = [[NSDictionary alloc]init];
// 这里可以接受到本地通知中心发送的消息
// dic = notification.userInfo;
// NSLog(@"user info = %@",[dic objectForKey:@"key"]);
// 图标上的数字减1
application.applicationIconBadgeNumber -=1;
}
#import <UIKit/UIKit.h>
@interface ZYAppDelegate : UIResponder <UIApplicationDelegate,UIAlertViewDelegate>
@property (strong,nonatomic)UIWindow *window;
@end
在 .m文件添加如下代码:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
case1:
NSLog(@"你可以干些别的事 比如跳转页面");
break;
default:
break;
}
}
- UILocalNotification 本地通知的应用实例
- iOS: 本地通知(UILocalNotification )的应用
- 本地通知UILocalNotification的用法
- UILocalNotification本地通知的使用方法
- UILocalNotification 本地通知的用法
- 本地通知 UILocalNotification的使用
- IOS本地通知(UILocalNotification)的基本使用
- UILocalNotification 本地通知无法删除的坑
- 本地通知UILocalNotification
- UILocalNotification 本地通知
- iOS本地通知UILocalNotification
- IOS 本地通知 UILocalNotification
- ios本地通知UILocalNotification
- 本地通知UILocalNotification
- iOS UILocalNotification本地通知
- 本地通知UILocalNotification
- iOS本地通知:UILocalNotification
- UILocalNotification本地通知介绍
- android pcm编解码
- 在DAO中如何获得session对象
- sed的使用举例 --Unix Shell
- win7系统使用种种
- u-boot-2009.08在mini2440上的移植
- UILocalNotification 本地通知的应用实例
- C++ 格式化sql 查询字符串带%的处理
- 关于typedef的用法
- Linux中fork()函数详解
- C++ ----- 快速入门
- leetcode之Longest Consecutive Sequence
- 项目实践--广告排期系统
- Unity3D教程使用小技巧大合集
- 二叉树算法