我們的團隊使用Ionic/Cordova
和IBM worklight(7.0)
。最近我們有機會嘗試react-native,我們需要將worklight
與應用程序集成在一起。如何將IBM Worklight與react-native應用程序集成?
我們如何將IBM worklight
與react-native應用程序集成?
我們的團隊使用Ionic/Cordova
和IBM worklight(7.0)
。最近我們有機會嘗試react-native,我們需要將worklight
與應用程序集成在一起。如何將IBM Worklight與react-native應用程序集成?
我們如何將IBM worklight
與react-native應用程序集成?
一般來說,你需要你創建一個陣營本地項目像任何其他,並添加到它的MobileFirst原生的iOS SDK,你也將它添加到任何其他原生的iOS項目(按照以下說明:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.0/hello-world/configuring-a-native-ios-with-the-mfp-sdk/)
您可以找到詳細的instrustions並在以下博客文章視頻:https://mobilefirstplatform.ibmcloud.com/blog/2015/06/03/react-native/
的博客文章確實提到了一體化的重要方面注意的:
下面我想的更多的一個惡魔主要代碼將iOS React Native與MobileFirst Platform Foundation集成在一起。代碼塊是從ResourceRequest.m文件導出到React Native JavaScript代碼中的MobileFirst Platform Foundation Adapter調用調用。在這部分代碼中,有兩個重要的React Native方法。一個是RCT_EXPORT_MODULE();這將允許您將本機類導出到React Native JavaScript中。另一個是RCT_EXPORT_METHOD(...)這個類明確地告訴React公開這個類的方法用於React Native javascript。導出下面的特定方法將傳入名爲「path」的路徑以及名爲「results」的回調。適配器調用獲取作爲JSON數據存儲到特定路徑的電影列表(此路徑最終不再需要)。然後,該數據作爲回調傳遞給React Native代碼。
#import <Foundation/Foundation.h>
#import "WLResourceRequest.h"
#import "ResourceRequest.h"
@implementation ResourceRequest
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(getJavaAdapter:(NSString *)path results:(RCTResponseSenderBlock)callback)
{
NSLog(@"Invoking GET Procedure...");
NSURL* url = [NSURL URLWithString:@"http://localhost:10080/HelloMobileFirst/adapters/MoviesAdapter/getStories"];
WLResourceRequest* resourceRequest = [WLResourceRequest requestWithURL:url method:WLHttpMethodGet];
[resourceRequest sendWithCompletionHandler:^(WLResponse *response, NSError *error) {
NSString* resultText;
if(error != nil){
resultText = @"Invocation failure.";
resultText = [resultText stringByAppendingString: error.description];
}
else{
resultText = response.responseText;
callback(@[[NSNull null], resultText]);
}
}];
}
@end