Get Unresolved Identifier for MMWormhole in Watch InterfaceController.swift

血红的双手。 提交于 2019-12-01 06:52:36

Here is my answer. After few days of struggle and help from a code mentor:

Problems are:

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.

Here is the brief step by step:

Objective C Bridge

  • Add App Groups for both iPhone App & Watch Ext
  • Add Objective C
  • Target on both
  • Build Settings: Set the *.h in relative path for both iOS & Watch Ext. set the *.h relative path. e.g. ../MMWormholeTest/MMWormholeTest/MMWormholeTest-Bridging-Header.h
  • Add Header Search path: ${PRODS_ROOT}/Headers , recursive for both IOS 7 Watch Ext

MMWormhole

  • Cocoa pods it.
  • Set pod 'MMWormhole', '~> 1.2.0’ target for both iOS & Watch Ext in Podfile
  • Set #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 awakeWithContext in 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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!