当应用程序在iOS 10中处于后台时,未收到推送通知

时间:2016-09-20 18:07:27

标签: ios objective-c firebase firebase-cloud-messaging firebase-notifications

我正在使用FCM(Firebase云消息传递)在iOS中发送推送通知。

当App处于前台状态时,我能够收到通知。但是当应用程序处于后台状态时,不会收到通知。每当应用程序进入前台状态时,只有那时才会收到通知。

我的代码是:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
   willPresentNotification:(UNNotification *)notification
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler

当App处于后台状态时:

        <t:dataTable id="data" var="phen"
            value="#{workflowLookup.dataModel}" 
            binding="#{workflowLookup.table}" 
            varDetailToggler="detailToggler">
            <f:facet name="header">
                <h:commandButton
                    id="expand-all-button"
                    action="#{detailToggler.expandAllDetails}"
                    value="Expand All" />                                  
                <h:commandButton
                    id="collapse-all-button"
                    action="#{workflowLookup.collapseAllDetails}" 
                    value="Collapse All" />
            </f:facet>
            ... (rest of table)

        </t:dataTable>

- 根本没有被召唤。

我在应用功能的后台模式中启用了推送通知和远程通知。但是App仍然没有收到通知。

我提到了一些StackOverflow问题,但无法解决问题。在iOS版本10中是否有任何要添加的内容或我的代码中有任何错误?

2 个答案:

答案 0 :(得分:8)

对于iOS 10,我们需要调用以下两种方法。

对于FOREGROUND状态

- (void)userNotificationCenter:(UNUserNotificationCenter *)center  willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler  
{  
    NSLog( @"Handle push from foreground" );  
    // custom code to handle push while app is in the foreground  
    NSLog(@"%@", notification.request.content.userInfo);
    completionHandler(UNNotificationPresentationOptionAlert);
} 

适用于背景状态

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler  
{  
    NSLog( @"Handle push from background or closed" );  
    // if you set a member variable in didReceiveRemoteNotification, you  will know if this is from closed or background  
    NSLog(@"%@", response.notification.request.content.userInfo);
    completionHandler();
}  

在此之前,我们必须添加UserNotifications框架并导入AppDelegate.h文件

#import <UserNotifications/UserNotifications.h>  
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>  

答案 1 :(得分:0)

我们已经与客户进行了许多测试,并且对该主题进行了大量研究。 iOS 10.x(尤其是10.3.x)在处理和显示推送时存在问题。解决该问题的唯一方法是升级到更新的iOS版本。

相关问题