【问题标题】:Flutter didReceiveRemoteNotification Not calledFlutter didReceiveRemoteNotification 未调用
【发布时间】:2020-06-30 18:17:15
【问题描述】:

我创建了一个支持推送通知但 application:didReceiveRemoteNotification:fetchCompletionHandler: 未触发的插件 仅在以下情况下收到通知:

  • 这样称呼它application:didReceiveRemoteNotification:
  • 在通知负载中将 content_available 设置为 true

我只是想知道为什么会这样,谁能帮我弄清楚如何使它与application:didReceiveRemoteNotification:fetchCompletionHandler: 一起工作?

【问题讨论】:

  • 当content_available 为真/1 时您是否已经收到通知?如果是这样,则没有问题,这是预期的行为。
  • 这似乎是flutter的问题,我在GitHub上添加了这个问题你可以在这里找到它:github.com/flutter/flutter/issues/52895

标签: ios flutter flutter-plugin


【解决方案1】:

你使用 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 中的选择器

- (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 Engine 的调试版本中确认它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多