簡體   English   中英

Flutter didReceiveRemoteNotification 未調用

[英]Flutter didReceiveRemoteNotification Not called

我創建了一個支持推送通知的插件,但application:didReceiveRemoteNotification:fetchCompletionHandler: not fire 僅在以下情況下收到通知:

  • 像這個application:didReceiveRemoteNotification:一樣調用它application:didReceiveRemoteNotification:
  • 在通知負載中將content_available設置為 true

我只是想知道為什么會發生這種情況,誰能幫我弄清楚如何讓它與application:didReceiveRemoteNotification:fetchCompletionHandler:

你使用 FlutterAppDelegate 作為 AppDelegte 的超類嗎? 在FlutterAppDelegate.mm,它取代方法respondsToSelector象下面

- (BOOL)respondsToSelector:(SEL)selector {
  if ([_lifeCycleDelegate isSelectorAddedDynamically:selector]) {
    return [self delegateRespondsSelectorToPlugins:selector];
  }
  return [super respondsToSelector:selector];
}

並且在FlutterPluginAppLifeCycleDelegate有實現

static const SEL selectorsHandledByPlugins[] = {
    @selector(application:didReceiveRemoteNotification:fetchCompletionHandler:),
    @selector(application:performFetchWithCompletionHandler:)};


- (BOOL)isSelectorAddedDynamically:(SEL)selector {
  for (const SEL& aSelector : selectorsHandledByPlugins) {
    if (selector == aSelector) {
      return YES;
    }
  }
  return NO;
}

所以為了調用application:didReceiveRemoteNotification:fetchCompletionHandler:它將調用 FlutterPluginAppLifeCycleDelegate 中的FlutterPluginAppLifeCycleDelegate

- (void)application:(UIApplication*)application
    didReceiveRemoteNotification:(NSDictionary*)userInfo
          fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
  for (NSObject<FlutterApplicationLifeCycleDelegate>* delegate in _delegates) {
    if (!delegate) {
      continue;
    }
    if ([delegate respondsToSelector:_cmd]) {
      if ([delegate application:application
              didReceiveRemoteNotification:userInfo
                    fetchCompletionHandler:completionHandler]) {
        return;
      }
    }
  }
}

也許一些插件打破了調用鏈。 這是我的猜測基礎 Flutter Engine 源代碼,我沒有在 Flutter 引擎的調試版本中確認它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM