我试图桥接Zendesk支持SDK以便在我的react native应用中进行渲染。
这是我通常在Objective-C中要做的事情:
#import "ViewController.h"
#import <ZendeskSDK/ZendeskSDK.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)ButtonPress:(id)sender {
[ZDKHelpCenter presentHelpCenterWithViewController:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
如何使用RCT_EXPORT_METHOD进行桥接?
此刻我得到了这样的东西:
#import "zendeskSupportView.h"
#import <ZendeskSDK/ZendeskSDK.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/UIView+React.h>
@implementation zendeskSupportView
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(findEvents:(RCTResponseSenderBlock)callback)
{
UIViewController *rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
rootController = [rootController topMostController];
[ZDKHelpCenter presentHelpCenterWithViewController:rootController];
}
@end
最佳答案
对于设置本机模块,您可以参考对本机module documentation进行反应,或者查看我在之前的项目中创建的gist of a small module,该项目会打开IOS设置应用。
在您的RCT_EXPORT_METHOD宏代码中,您将需要调用[ZDKHelpCenter presentHelpCenterWithViewController:self];
。由于此函数中没有直接可用的控制器实例,因此您可以执行以下操作:
UIViewController *rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
rootController = [rootController topMostController];
[ZDKHelpCenter presentHelpCenterWithViewController:rootController];
上面的代码将ios控制器堆栈中最顶层的控制器传递给ZendDeskHelpCenter。
关于javascript - 用于Zendesk支持SDK的RCT_EXPORT_METHOD,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41500133/