iOS应用在前台时弹出本地通知

在appdelegate中实现如下方法

//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {//应用处于前台时的远程推送接受

    } else {//应用处于前台时的本地推送接受
        completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);//
    }
}

你可能感兴趣的:(IOS)