在iOS8中本地通知不能显示的问题

来源:互联网 发布:java中的观察者模式 编辑:程序博客网 时间:2024/05/20 12:47

需要在方法前面手动添加以下代码

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])  {

 [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil]]; 

 }


创建本地推送通知对象
UILocalNotification *ln = [[UILocalNotificationalloc] init];

设置本地推送通知属性
推送通知的触发时间(何时发出推送通知)
@property(nonatomic,copy)NSDate *fireDate;
推送通知的具体内容
@property(nonatomic,copy)NSString *alertBody;
锁屏界面显示的小标题(完整小标题:滑动来 + alertAction
@property(nonatomic,copy)NSString *alertAction;
音效文件名
@property(nonatomic,copy)NSString *soundName;
app图标数字
@property(nonatomic)NSInteger applicationIconBadgeNumber;
调度本地推送通知(调度完毕后,推送通知会在特地时间fireDate发出)
[[UIApplicationsharedApplication] scheduleLocalNotification:ln];

获得被调度的所有本地推送通知(等待发出的通知)
@property(nonatomic,copy)NSArray *scheduledLocalNotifications;
(已经发出且过期的推送通知就算调度结束,会自动从这个数组中移除)

取消调度本地推送通知
- (void)cancelLocalNotification:(UILocalNotification *)notification;
- (
void)cancelAllLocalNotifications;

立即发出本地推送通知(使用价值:app在后台运行的时候)
- (void)presentLocalNotificationNow:(UILocalNotification *)notification;

每隔多久重复发一次推送通知
@property(nonatomic)NSCalendarUnit repeatInterval;

点击推送通知打开app时显示的启动图片
@property(nonatomic,copy)NSString *alertLaunchImage;

附加的额外信息
@property(nonatomic,copy)NSDictionary *userInfo;

时区
@property(nonatomic,copy)NSTimeZone *timeZone;
(一般设置为[NSTimeZonedefaultTimeZone] ,跟随手机的时区)

当用户点击本地推送通知,会自动打开app,这里有2种情况
app
并没有关闭,一直隐藏在后台
app进入前台,并会调用AppDelegate的下面方法(并非重新启动app
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification;

app
已经被关闭(进程已死)
启动app,启动完毕会调用AppDelegate的下面方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
launchOptions参数通过UIApplicationLaunchOptionsLocalNotificationKey取出本地推送通知对象

0 0
原创粉丝点击