gpt4 book ai didi

ios - 在 Watch InterfaceController.swift 中获取 MMWormhole 的未解析标识符

转载 作者:搜寻专家 更新时间:2023-10-31 19:35:00 27 4
gpt4 key购买 nike

我的 Apple Watch 项目是用 Swift 编写的。我已经使用 CocoaPods 安装了 MMWormhole,我按照这些链接中的描述创建了桥接头:

http://bencoding.com/2015/04/15/adding-a-swift-bridge-header-manually/

How to call Objective-C code from Swift

当我创建桥接 header 时,我将其定位到我的 iPhone 应用程序,并观看扩展。

桥接 header.h,我有这个:

#import "MMWormhole.h"

在我的 iPhone 应用程序 View Controller 中,我有这个:

import UIKit
import Foundation

let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")

没有提示。

但是,在我的 watch 界面 Controller 中,我有这个:

import WatchKit
import Foundation

...

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")
}

它提示“使用未解析的标识符 MMWormhole”。

我什至尝试使用#import "MMWormholeClient.h"但没有什么可以解决这个问题。

我在创建桥接头时也尝试过,只针对 iphone 应用程序。但是仍然...不起作用。

我还在 WatchExtension 的 podfile 目标中创建了 pod 'MMWormhole', '~> 1.2.0'。但还是没有在Watch接口(interface)Controller中识别出MMWormhole

我错过了什么吗?

这是我的项目:https://www.dropbox.com/s/tsajeoopnghyl1g/MyTestCocoData.zip?dl=0

最佳答案

这是我的答案。经过几天的努力和代码导师的帮助:

问题是:

1) The Objective-C bridge has to set the correct path and header search path so both IOS & WatchExt can use
2) The PodFile in MMWormhole must target for both iOS & WatchExt.
3) The code in MMWormhole npm page is not correct. Move the instantiation of MMWormhole out and be a class Variable.

这里是简要的步骤:

Objective C 桥

  • 为 iPhone 应用和 Watch Ext 添加应用组
  • 添加 objective-c
  • 同时兼顾
  • build设置:在 iOS 和 Watch Ext 的相对路径中设置 *.h。设置 *.h 相对路径。例如../MMWormholeTest/MMWormholeTest/MMWormholeTest-桥接-Header.h
  • 添加标题搜索路径: ${PRODS_ROOT}/Headers ,递归 IOS 7 Watch Ext

MM虫洞

  • cocoa pod 。
  • 在 Podfile 中为 iOS 和 Watch Ext 设置 pod 'MMWormhole', '~> 1.2.0' 目标
  • 在桥接头文件中设置#import “MMWormhole.h”。
  • 在 ViewController 和 InterfaceOController 中,将 wormhole 设置为类范围变量。例如变种虫洞:MMWormhole!
  • 在 ViewDidLoad 和 awakeWithContext 中实例化 MMWormhole在 WatchExt 中,在 awakeWithContext 中设置监听器,并使用 self.lable.setText 因为关闭。例如self.label.setText(messageObject!as!String)
  • 无需像 Stack overflow 中的其他一些 MMWormhole 示例那样注册接收器。

关于ios - 在 Watch InterfaceController.swift 中获取 MMWormhole 的未解析标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30828354/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com