React Native クライアント・サイド API リファレンス (ここ) を参照してください。
WLAuthorizationManager.obtainAccessToken("").then((token)=>{console.log('--> pingMFP(): Success ',token);varresourceRequest=newWLResourceRequest("/adapters/javaAdapter/resource/greet/",WLResourceRequest.GET);resourceRequest.setQueryParameters({name:"world"});resourceRequest.send().then((response)=>{// Will display "Hello world" in an alert dialog.
alert("Success: "+response.responseText);},(error)=>{console.error(error);alert("Failure: Resource Request");});},(error)=>{console.error(error);alert("Failed to connect to MobileFirst Server");});
「Ping MobileFirst Server」ボタンをクリックすると、Connected to MobileFirst Server と表示されます。
アプリケーションが MobileFirst Server に接続できる場合、デプロイした Java アダプターを使用してリソース要求呼び出しが行われます。その場合、アダプター応答がアラートに表示されます。
IBM MobileFirst JSONStore の React Native SDK
IBM Mobile Foundation JSONStore は、軽量で文書志向のストレージ・システムを提供する、オプションのクライアント・サイド API です。JSONStore は JSON 文書の永続ストレージを有効にします。アプリケーション内の文書は、デバイスがオフラインの時でも JSONStore 内で使用可能です。この永続的で常に使用可能なストレージは、例えばデバイスで使用できるネットワーク接続がない時などに、ユーザーに文書へのアクセス権限を与えるのに役立ちます。
インストール
React Native アプリケーションの IBM MobileFirst JSONStore SDKは IBM MobileFirst Foundation SDK に依存しています。IBM MobileFirst Foundation SDK をご使用のアプリケーションに追加します。
vardogs=newJSONStoreCollection('dogs');WLJSONStore.openCollections(['dogs']);// Provide the name of the collection as a string.
コレクションにデータを追加
コレクションに JSON データを追加します。
varhachi={"name":"Hachiko","breed":"Akita","country":"Japan"};dogs.addData(hachi).then(()=>{// Data was added to the collection successfully.
}).catch((err)=>{// Error adding data. See the err object for more information on the error
})
コレクションからデータを照会
任意の JSONStoreCollection.find* API を使用して、コレクションを照会します。
JSON データの拡張フィルター処理と照会に、JSONStoreQueryPart と JSONStoreQuery API を使用します。
dogs.findAllDocuments().then((result)=>{// result will have all the documents in the collection
// E.g. [ {"json": {"name":"Hachiko","breed":"Akita","country":"Japan"},"_id":2}]
}).catch((error)=>{console.error("Error finding docs "+JSON.stringify(error));});
コレクションのクローズ、クリア、および破棄
コレクションをクローズすると、openCollections API の使用に対してコレクションがオープンするまで、その後のアクセスのために JSONStore コレクションがクローズされます。
WLJSONStore.closeAll()
コレクションをクリアするとコレクションからのすべての文書が削除されますが、破棄はされません。
dogs.clearCollection().then(()=>{// All documents cleared successfully
}).catch((err)=>{// An error occurred while clearing the collection.
})
スキーマとフィーチャーをセットアップしたら、クライアント・サイド API を使い始めることができます。
API の使用例
varuseClientCache=false;//True (default)
varfeatureId='featureId';varpropertyId='propertyId';MFLiveUpdate.obtainConfiguration(useClientCache).then(result=>{console.log('Is feature enabled for'+featureId+':'+result.isFeatureEnabled('featureId'));console.log('Property value for the '+propertyId+'is :'+result.getProperty('propertyId'));}).catch(err=>console.log('There was an error:'+err))
Inclusive terminology note: The Mobile First Platform team is making changes to support
the IBM® initiative to replace racially biased and other discriminatory language in our code and content
with more inclusive language. While IBM values the use of inclusive language, terms that are outside of
IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other
industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the
documentation to reflect those changes.