问题描述
我的 Apple Watch 项目使用 Swift.我已经使用 CocoaPods 安装了 MMWormhole,我按照这些链接中的描述创建了桥接头:
My Apple Watch project is in Swift. I have used CocoaPods to install MMWormhole,and I created the bridging header as described in these links:
http://bencoding.com/2015/04/15/adding-a-swift-bridge-header-manually/
当我创建桥接头时,我将它定位到我的 iphone 应用程序,并观看 Extension.
When I created the bridging header, I target it to my iphone app, and also watch Extension.
桥接 header.h,我有这个:
The bridging header.h, I have this:
#import "MMWormhole.h"
在我的 iPhone 应用视图控制器中,我有这个:
In my iPhone app View Controller, I have this:
import UIKit
import Foundation
let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")
没有抱怨.
但是,在我的手表接口控制器中,我有这个:
However, in my watch Interface Controller, I have this:
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".
And it complains about "Use of unresolved identifier MMWormhole".
我什至尝试使用 #import "MMWormholeClient.h" 但没有什么可以解决这个问题.
I even try to use #import "MMWormholeClient.h" but nothing can resolve this problem.
我在创建桥接头时也尝试过,只针对 iphone 应用程序.但仍然......不起作用.
I also try when creating the bridging header, just target on the iphone App. But still... doesn't work.
我还在 WatchExtension 的 podfile 目标中制作了 pod 'MMWormhole', '~> 1.2.0'.但是仍然没有在Watch interfaceController 中识别出MMWormhole
I also make pod 'MMWormhole', '~> 1.2.0' in the podfile target for WatchExtension. but still not identified MMWormhole in the Watch interfaceController
我错过了什么吗?
这是我的项目:https://www.dropbox.com/s/tsajeoopnghyl1g/MyTestCocoData.zip?dl=0
推荐答案
这是我的答案.经过几天的挣扎和代码导师的帮助:
Here is my answer. After few days of struggle and help from a code mentor:
问题是:
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 Bridge
- 为 iPhone 应用和应用添加应用组观看分机
- 添加目标 C
- 同时瞄准两个目标
- 构建设置:在 iOS & 的相对路径中设置 *.h观看分机.设置 *.h 相对路径.例如../MMWormholeTest/MMWormholeTest/MMWormholeTest-Bridging-Header.h
- 添加标题搜索路径: ${PRODS_ROOT}/Headers ,对 IOS 7 Watch Ext 递归
MMWormhole
- 可可豆荚.
- 为 iOS & 设置 pod 'MMWormhole', '~> 1.2.0' 目标在 Podfile 中观看 Ext
- 在桥接头文件中设置 #import MMWormhole.h".
- 在 ViewController 和InterfaceOController,将虫洞设置为类作用域变量.例如var 虫洞:MMWormhole!
- 在ViewDidLoad和awakeWithContext中实例化MMWormhole在 WatchExt 中,在awakeWithContext 中设置侦听器,由于闭包使用self.lable.setText.例如self.label.setText(messageObject!as!String)
- 无需像堆栈溢出中的其他一些 MMWormhole 示例中所示注册接收器.
这篇关于在 Watch InterfaceController.swift 中获取 MMWormhole 的未解析标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!