依照官網所描述的步驟
新建SelfModule.m/.h文件,並導入project-swift.h,對外定義暴露jumpNextPage(params : String)方法
#import "SelfModule.h" #import "Project-Swift.h" #import "Project-Bridging-Header.h" @implementation SelfModule #pragma clang diagnostic push //关闭unknow selector的warrning #pragma clang diagnostic ignored "-Wundeclared-selector" @synthesize weexInstance; WX_EXPORT_METHOD(@selector(jumpNextPage)) #pragma clang diagnostic pop @end
新SelfModule.swift文件,擴充SelfModule方法
public extension SelfModule{ public func jumpNextPage(params : NSString){ let controller = UIViewCtroller() weexInstance.viewController.navigationController?.pushViewController(controller, animated:true) } }
在AppDelegate中註冊Module,
WXSDKEngine.registerModule("self_module", with: NSClassFromString("SelfModule"))
結果提示
method:jumpNextPage for module:self_module doesn't exist, maybe it has not been registered [;
在Android上是沒有任何問題的,但在iOS上報錯,求解原因
你看一下導入橋接文件沒有,在Project-Bridging-Header.h這個裡面