您的位置:首页 > 移动开发

applicationIconBadgeNumber和localNotification申请通知弹出

2015-12-19 23:22 330 查看
在application代理中添加如下加粗方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
return YES;
}

#import "ViewController.h"

@interface ViewController ()
- (IBAction)noti:(UIButton *)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

}

- (IBAction)noti:(UIButton *)sender {
UILocalNotification *noti = [[UILocalNotification alloc]init];
noti.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
noti.alertBody = @"alertBody";
noti.alertAction = @"alertAction";
noti.applicationIconBadgeNumber = 4;
UIApplication *app = [UIApplication sharedApplication];
[app cancelAllLocalNotifications];
[app scheduleLocalNotification:noti];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: