【发布时间】:2018-05-03 07:55:04
【问题描述】:
我正在使用 Objective-c 开发一个 iOS 本机应用程序,我必须在其中嵌入一个基于 React 开发的视图,并且我已经完成了这项工作,但是这些类是我的系统本地的,现在我已将这些文件上传到我的服务器上并想在我的 React 应用程序中将此类称为 URL。我怎么能做这个任何建议。我试过制作 NSURL 实例并传递给 RCTBridge 但没有用。任何帮助将不胜感激。
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"home.ios" fallbackResource:nil];
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:nil];
NSDictionary *props = @{@"bearer_token" : @"token", @"area_id":@"areadId"};
rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"Order" initialProperties:props];
这里的 home.ios 是本地放置在我系统中的文件路径,现在我已将其托管在服务器上并从那里调用,如下所示:
NSURL *jsCodeLocation = [[NSURL alloc] initWithString:@"http://**************-react.s3-website.ap-south-1.amazonaws.com/home.ios.js"];
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:nil];
NSDictionary *props = @{@"bearer_token" : bearerToken ? bearerToken : @"bearer", @"area_id":SELECTED_AREA_ID};
rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"Order" initialProperties:props];
rootView.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 112);
[self.view addSubview:rootView];
【问题讨论】:
标签: ios objective-c reactjs react-native