- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState == UIApplicationStateActive) {
UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil) {
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:10];
notification.fireDate=date ;
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.alertBody= [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.userInfo = userInfo;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[self playSound];
}
} else {
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
if(badge > 0)
{
badge--;
[UIApplication sharedApplication].applicationIconBadgeNumber = badge;
}
// [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[self readInfoNetwork:[userInfo objectForKey:@"bId"]];
[self readUserInfo:userInfo];
}
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
if (application.applicationState != UIApplicationStateActive) {
NSDictionary *userInfo = notification.userInfo;
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
if(badge > 0)
{
badge--;
[UIApplication sharedApplication].applicationIconBadgeNumber = badge;
}
// [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[self readInfoNetwork:[userInfo objectForKey:@"bId"]];
[self readUserInfo:userInfo];
[application cancelLocalNotification:notification];
}
}
我这样写还是不会有横幅出来,而且在读取本地的逻辑也有问题