推送通知--本地推送通知

@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

   

    //1.创建本地通知的对象

    UILocalNotification *notification = [[UILocalNotification alloc] init];

    

    //2.设置通知触发的时间

    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

    

    //3.设置弹出提示的内容

    notification.alertBody = @"吃饭啦啦啦啦";

    

    //4.设置按钮的标题

    notification.alertAction = @"提醒";

    

    

    //注册本地通知,注册之后,通知才会生效

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

    

    //设置消息提醒的数目

    [UIApplication sharedApplication].applicationIconBadgeNumber = 3;

}

//UIAppDelegate中设置



@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

   

    //iOS8以后需要设置以下代码

    UIUserNotificationType type = UIUserNotificationTypeBadge |UIUserNotificationTypeAlert | UIUserNotificationTypeSound;

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    return YES;

}


- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

{

    NSLog(@"lalalala");

    application.applicationIconBadgeNumber = 0;

}


你可能感兴趣的:(推送通知)