iOS开发 实现本地推送通知
1、创建工程项目和视图控制器
1、创建一个Sing View Application工程项目;
2、为项目命名,生成工程文件。

2、注册通知
在AppDelegate.m中application: didFinishLaunchingWithOptions:方法注册通知:
UIUserNotificationType types = UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
沫珠 [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

3、接收本地通知回调方法
在AppDelegate.m实现UIApplicationDelegate方法:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification;

4、创建本地通知并安排执行
1、初始化UILocalNotification;
2、设置延时时间.fireDate;
3、设置通知显示内容.alertBody;
4、设置徽标数.applicationIconBadgeNumber;
压总5、设置通知被触发时播放的声音.notification.soundName;
6、设置通知详情.userInfo;
7、安排触发通知。

5、取消所有通知
遍历所有通知,调用方法取消。
- (void)cancelLocalNotification:(UILocalNotification *)notification;

6、运行Run

7、在前台接收到推送,使用UIAlertController弹出提示。

8、在后台接收到推送,使用UIAlertController弹出提示。

9、如果您喜欢,请按投票;如果有疑问睡驼侧,欢迎一起探讨。
