繁体   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