Flutter:类型"UIApplication"没有成员"openSettingsURLString" [英] Flutter: Type 'UIApplication' has no member 'openSettingsURLString'

查看:359
本文介绍了Flutter:类型"UIApplication"没有成员"openSettingsURLString"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使geolocator 2.1.0插件与我的ios xcode项目一起使用,并在运行pod install之后获得以下2个错误提示

I am attempting to get the geolocator 2.1.0 plugin to work with my ios xcode project and get the following 2 erros after I run pod install

类型'UIApplication'没有成员'openSettingsURLString' 和 'OpenExternalURLOptionsKey'不是'UIApplication'的成员类型

Type 'UIApplication' has no member 'openSettingsURLString' and 'OpenExternalURLOptionsKey' is not a member type of 'UIApplication'

已采取的步骤.

  1. 我打开一个新的Flutter项目(无论是否选中"Swift支持",都会发生错误)-获取默认应用.

  1. I open a new Flutter project(Error occurs with or without 'Swift Support' checked) -get the default app.

仅使用- geolocator 更新我的pubspec.yaml文件 a>:^ 2.1.0

Update my pubspec.yaml file with only - geolocator: ^2.1.0

希望我缺少一些简单的东西.感谢您的高级帮助.

Hopefully I am missing something something simple. Thanks for the help in advanced.

Podfile看起来像这样

Podfile looks like this

(我已经用'config.build_settings ['SWIFT_VERSION'] ='4.1''更新了文件.

(I have updated the file with ' config.build_settings['SWIFT_VERSION'] = '4.1'').

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

def parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  pods_ary = []
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) { |line|
      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
      plugin = line.split(pattern=separator)
      if plugin.length == 2
        podname = plugin[0].strip()
        path = plugin[1].strip()
        podpath = File.expand_path("#{path}", file_abs_path)
        pods_ary.push({:name => podname, :path => podpath});
      else
        puts "Invalid plugin specification: #{line}"
      end
  }
  return pods_ary
end

target 'Runner' do
  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')

  # Flutter Pods
  generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
  if generated_xcode_build_settings.empty?
    puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
  end
  generated_xcode_build_settings.map { |p|
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
      symlink = File.join('.symlinks', 'flutter')
      File.symlink(File.dirname(p[:path]), symlink)
      pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
    end
  }

  # Plugin Pods
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
    symlink = File.join('.symlinks', 'plugins', p[:name])
    File.symlink(p[:path], symlink)
    pod p[:name], :path => File.join(symlink, 'ios')
  }
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '4.1'
    end
  end
end

推荐答案

(YOUR_PROJECT)/ios/Podfile中的目标运行器中添加use_frameworks!.

Add use_frameworks! in target Runner in your (YOUR_PROJECT)/ios/Podfile.

target 'Runner' do
  use_frameworks!  # required by Geolocator

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')

地理定位器的较旧版本,例如^1.6.3,需要将SWIFT_VERSION设置为4.04.1.

Older versions of the geolocator, such as ^1.6.3, requires SWIFT_VERSION set to 4.0 or 4.1.

但是geolocator版本2.1.0使用的是permission_handler版本2.1.1,需要SWIFT_VERSION 4.2.

But the geolocator version 2.1.0, uses permission_handler version 2.1.1, which requires SWIFT_VERSION 4.2.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '4.2'  # required by Geolocator
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

我能够使用flutter 0.11.9和Xcode 10.1在我的应用程序中成功构建和使用geolocator版本2.1.0.

I was able to successfully build and use geolocator version 2.1.0 in my app, using flutter 0.11.9 and Xcode 10.1.

这篇关于Flutter:类型"UIApplication"没有成员"openSettingsURLString"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆