1. 程式人生 > >iOS應用在前臺時彈出本地通知

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);// } }