0

我是 XcodeGen 的初学者并尝试将 iOS 14 的小部件目标添加到我的应用程序

Widget:
type: app-extension
platform: iOS
settings:
  INFOPLIST_FILE: PIAWidget/Info.plist
  PROVISIONING_PROFILE_SPECIFIER_Release: Development - Widget Extension
  OTHER_LDFLAGS: $(inherited) -framework WidgetKit
configFiles:
  Debug: Configuration/AppExtension-iOS.xcconfig
  Release: Configuration/AppExtension-iOS.xcconfig
sources:
  - path: Widget
    name: "Extension: Widget"

在project.yml的选项中,部署目标是iOS 13.0

 options:
  deploymentTarget:
    macOS: "10.14"
    iOS: "13.0"
    tvOS: "13.0"
  settingPresets: none
  createIntermediateGroups: true
  carthageExecutablePath: Vendor/carthage.command
  carthageBuildPath: ${APP_CARTHAGE_BUILD_PATH}
  usesTabs: false
  indentWidth: 3
  tabWidth: 3

在小部件 swift 类中,有@main一个要求我添加:@available

@available(iOSApplicationExtension 14.0, *)
@main 

但添加后,它仍然向我显示该错误:

'main()' is only available in application extensions for iOS 14.0 or newer

这就是为什么,我想也许我必须deploymentTarget在小部件部分添加一个。当我搜索它应该是这样的:

  Widget:
    type: app-extension
    platform: iOS
    deploymentTarget:
      iOS: "14.0"
    settings:
      INFOPLIST_FILE: PIAWidget/Info.plist
      PROVISIONING_PROFILE_SPECIFIER_Release: Piavet Development - Widget Extension
      OTHER_LDFLAGS: $(inherited) -framework WidgetKit
    configFiles:
      Debug: Configuration/AppExtension-iOS.xcconfig
      Release: Configuration/AppExtension-iOS.xcconfig
    sources:
      - path: Widget
        name: "Extension: Widget" 

但我仍然得到错误。有人可以帮我吗?

4

1 回答 1

1

像这样将 deploymentTarget 从 14.0 更改为 14.1

    deploymentTarget:
      iOS: "14.1"
于 2021-04-24T01:08:30.253 回答