本地通知

  1. 原生方法实现

    pragma mark - private method

    // 启动本地通知
    - (void)setupLocalNoti
    {
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
    return;

    localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    // Notification details
    localNotif.alertBody = @"吃饭时间到了,通知提醒 。。。。。。。。";
    // Set the action button
    localNotif.alertAction = @"View";
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;
    // Specify custom data for the notification
    localNotif.userInfo = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    // NSArray * array = [[UIApplication sharedApplication] scheduledLocalNotifications];
    // [[UIApplication sharedApplication] cancelAllLocalNotifications];
    // [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
    }

    pragma mark - 本地通知 回调

    - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotif
    {
    NSLog(@"======%@",localNotif.alertBody);
    }

2.第三方实现

import "ACPReminder.h"

pragma mark - private method

// 启动本地通知
- (void)setupLocalNoti
{
ACPReminder * localNotifications = [ACPReminder sharedManager];

//Settings
localNotifications.messages = @[@"11111", @"22222", @"33333", @"444444", @"55555"];
localNotifications.timePeriods = @[@(1),@(2),@(3)]; //days
localNotifications.appDomain = @"com.mydomain.appName";
localNotifications.randomMessage = NO; //By default is NO (optional)
localNotifications.testFlagInSeconds = YES; //By default is NO (optional) --> For testing purpose only!
localNotifications.circularTimePeriod = YES; // By default is NO (optional)

[localNotifications createLocalNotification];
}

pragma mark - 本地通知 回调

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotif
{
NSLog(@"======%@",localNotif.alertBody);
}

posted on 2015-01-04 13:55  liman1990  阅读(100)  评论(0)    收藏  举报

导航