微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Platform.select{}如何工作?在iOS上执行时获取未定义的BuildConfig

如何解决Platform.select{}如何工作?在iOS上执行时获取未定义的BuildConfig

我正在build.gradle和info.plist中进行配置,我需要使用▼来启动运行时间

import { Platform } from 'react-native';
import BuildConfig from 'react-native-build-config';

在iPhone上测试时我没有问题,但是当我在Android上执行此操作时,在 Buildconfig 上却未定义,尽管BuildConfig获取错误的Info.plist属性,但BuildConfig是未定义的但它应该指向属性而不是BuildConig本身。
当它在Android上运行时,它可以完美地在Android上运行,但在iOS部分或GlobalConfig.b.CFBundleURLTypes[0].CFBundleURLSchemes[1]上运行失败。

失败情况:

 // Deeplinks -----------------------
  public static readonly DEEPLINK_INTENT_HOST: string = Platform.select({
    ios: BuildConfig.CFBundleURLTypes[0].CFBundleURLSchemes[1],android: BuildConfig.INTENT_FILTER_HOST,default: ''
  });

// --------------------------------------------- --------------------

// Deeplinks -----------------------
      public static readonly DEEPLINK_INTENT_HOST: string =
       Platform.select({
        ios: (BuildConfig.CFBundleURLTypes || [])[0].CFBundleURLSchemes[1],default: ''
      });

// --------------------------------------------- --------------------

  // Deeplinks -----------------------
  public static b: any = BuildConfig;
  public static readonly DEEPLINK_INTENT_HOST: string = Platform.select({
    ios: GlobalConfig.b.CFBundleURLTypes[0].CFBundleURLSchemes[1],android: GlobalConfig.b.INTENT_FILTER_HOST,default: ''
  });

工作场景:

  // Deeplinks -----------------------
  public static readonly DEEPLINK_INTENT_HOST: string = Platform.OS == 'ios' ? BuildConfig.CFBundleURLType[0].CFBundleURLSchemes[1] : BuildConfig.INTENT_FILTER_HOST;
 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。