本文介绍了在Watch InterfaceController.swift中获取MMWormhole的未解析标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我的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-manual / 如何从Swift调用Objective-C代码当我创建桥接头时,我将其定位到我的iphone应用程序,并观看扩展。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应用程序View Controller中,我有:In my iPhone app View Controller, I have this:import UIKitimport Foundationlet wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")并且没有抱怨。但是,在我的手表界面控制器中,我有这个:However, in my watch Interface Controller, I have this:import WatchKitimport 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".我甚至尝试使用#importMMWormholeClient.h,但没有什么可以解决这个问题。I even try to use #import "MMWormholeClient.h" but nothing can resolve this problem.我还在创建桥接头时尝试,只需在iphone App上定位。但仍然......不起作用。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界面中识别MMWormholeI 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 use2) 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.以下是一步一步的简要说明:Here is the brief step by step: Objective C Bridge 为iPhone App&添加应用程序组观看分机 添加目标C 两者上的目标 构建设置:设置* .h in iOS和&的相对路径观看Ext。设置* .h相对路径。例如 ../ MMWormholeTest / MMWormholeTest / MMWormholeTest-Bridging-Header.h 添加标题搜索路径:$ {PRODS_ROOT} /标题,递归IOS 7 Watch ExtAdd App Groups for both iPhone App & Watch ExtAdd Objective CTarget on bothBuild Settings: Set the *.h in relative path for both iOS & Watch Ext. set the *.h relative path. e.g.../MMWormholeTest/MMWormholeTest/MMWormholeTest-Bridging-Header.hAdd Header Search path: ${PRODS_ROOT}/Headers , recursive for both IOS 7 Watch Ext MMWormhole Cocoa pods吧。 为iOS和iPad设置pod'MMWormhole','〜> 1.2.0'目标在Podfile中观察Ext 在桥接头文件中设置#importMMWormhole.h。 在ViewController和& InterfaceOController,将wormhole设置为类范围变量。例如var wormhole:MMWormhole! 在ViewDidLoad中实例化MMWormhole,在WatchExt中实现awakeWithContext ,在awakeWithContext中设置监听器,并因封闭而使用self.lable.setText。例如self.label.setText(messageObject!as!String) 无需注册接收器,如堆栈溢出中的其他一些MMWormhole示例所示。Cocoa pods it.Set pod 'MMWormhole', '~> 1.2.0’ target for both iOS & Watch Ext in PodfileSet #import "MMWormhole.h" in bridging header file.in both ViewController & InterfaceOController, set wormhole as class scope variable. e.g. var wormhole:MMWormhole!Instantiate MMWormhole in ViewDidLoad and awakeWithContextin WatchExt, set listener in awakeWithContext , and use self.lable.setText because of closure. e.g. self.label.setText(messageObject! as! String)No need to register receiver as shown in some other MMWormhole examples in Stack overflow. 这篇关于在Watch InterfaceController.swift中获取MMWormhole的未解析标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 14:52