WL.JSONStore is undefined error in IBM mobilefirst - ibm-mobilefirst

I am getting WL.JSONStore is undefined error in mobile browser simulator while I am trying to use JSONStore in my mobile application.I am using IBM mobilefirst (version 8.0.0-2017091111).
function wlCommonInit(){
WL.JSONStore.init(collections, options).then(function () {
alert("intialized successfully");
}).fail(function (errorObject) {
alert("failed to initialize collection\n"+ JSON.stringify(errorObject));
});
document.getElementById("btn_submit").addEventListener("click", onSubmit, false);
}
function onSubmit(){
var collectionName="people";
var data={firstName:$('#first').val(),middleName:$('#middle').val(),lastName:$('#last').val()};
WL.JSONStore.get(collectionName).add(data, options).then(function () {
alert("added data successfully");
}).fail(function (error) {
});
}

Could you specify which version of 'cordova-plugin-mfp-jsonstore' your app is using (run command 'cordova plugin ls').
Did you follow this tutorial
Link

Add cordova jsonstore plugin
cordova plugin add cordova-plugin-mfp-jsonstore
See more: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/jsonstore/cordova/#adding-jsonstore
https://www.npmjs.com/package/cordova-plugin-mfp-jsonstore

Related

React native Agora 3.5.0 TypeError: _reactNativeAgora.RtcEngineContext is not a constructor

I updated our apss agora version to 3.5.0 because it wasn't working on ios 15. nwo it works on ios 15 but does not work on android.
Code starts exactly of this
https://github.com/AgoraIO-Community/react-native-agora/blob/master/example/src/examples/basic/JoinChannelVideo/JoinChannelVideo.tsx
UNSAFE_componentWillMount() {
this._initEngine();
}
componentWillUnmount() {
this._engine?.destroy();
}
_initEngine = async () => {
this._engine = await RtcEngine.createWithContext(
new RtcEngineContext(config.appId)
);
this._addListeners();
await this._engine.enableVideo();
await this._engine.startPreview();
await this._engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
await this._engine.setClientRole(ClientRole.Broadcaster);
};
And it says
TypeError: _reactNativeAgora.RtcEngineContext is not a constructor
You're using UNSAFE_componentWillMount which could be causing issues.

Share a URL as post in Facebook App from React-Native App

I have a React-native app, from which I want share my website's URL in a Facebook post.
My current code is :
import Share from "react-native-share";
const shareToFacebook = async () => {
const shareOptions = {
social: Share.Social.FACEBOOK,
message: "Test message",
url: "https://example.com/",
};
try {
const ShareResponse = await Share.shareSingle(shareOptions);
console.log(ShareResponse);
} catch (error) {
console.log("Error =>", error);
}
};
but this solution ,opens Facebook in the browser. Is there any way to open the actual Facebook app ?
Facebook offers an SDK for sharing posts, you can use that SDK with react-native-fbsdk-next library. It shows an in-app modal. I think showing an in-app modal is better than the open the Facebook app or open a browser because some people do not have Facebook on their phones.
You can test the share function before installing the library, follow below steps:
# clone the react-native-fbsdk-next
git clone https://github.com/thebergamo/react-native-fbsdk-next.git
# go to the test project
cd RNFBSDKExample
# install dependencies
npm install
# run the project
npm run android
Example code (from README page):
// ...
import { ShareDialog } from 'react-native-fbsdk-next';
// ...
// Build up a shareable link.
const shareLinkContent = {
contentType: 'link',
contentUrl: "https://facebook.com",
contentDescription: 'Wow, check out this great site!',
};
// ...
// Share the link using the share dialog.
shareLinkWithShareDialog() {
var tmp = this;
ShareDialog.canShow(this.state.shareLinkContent).then(
function(canShow) {
if (canShow) {
return ShareDialog.show(tmp.state.shareLinkContent);
}
}
).then(
function(result) {
if (result.isCancelled) {
console.log('Share cancelled');
} else {
console.log('Share success with postId: '
+ result.postId);
}
},
function(error) {
console.log('Share fail with error: ' + error);
}
);
}
Read more about Facebook Sharing Feature.

Socket.io expo react native clients repeatedly changing socket.id and shows disconnect=true

I am new to socket.io and was using guide https://snack.expo.io/#alexandrius/socket.io-client
On my server side (node.js) i see that socket.id keeps changing repeatedly
And on by expo client side in console.log i see :
Here is my code for client side:
componentDidMount() {
//console.log(socket);
//socketIO();
this.socket = io(URL, { transports: ["websocket"] });
this.socket.on("connect", () => {
this.setState({ isConnected: true });
});
this.socket.on("ping", (data) => {
console.log(data);
});
GetLocation();
}
When i connect to web page from phone it fires up socket and on server side does not change id repeatedly.
No sure is there any bug with expo react native socke.io library or i am doing something wrong
I fixed it my upgrading my expo to the version 36

Application not connecting to Worklight server

I am using WL.Client.connect(options) to connect to worklight server from my hybrid app and its returing this error (please refer to the attachment).
I have checked the WL console, my app and adapters are deployed without any issues.
Could not find any error messages in the logs.
function performWlConnect() {
return new Promise(function (resolve, reject) {
// Worklight server connection callback configuration
var wlConnectOptions = {
onSuccess: resolve,
onFailure: reject
};
logger.info('Connecting to the worklight server side...');
// Perform connection to the server side
WL.Client.connect(wlConnectOptions);
});
}
Try with a simple connect and print the error you're getting, it might help you better diagnose your flow.
function wlCommonInit() {
WL.Client.connect({onSuccess:onConnectSuccess, onFailure:onConnectFailure});
}
function onConnectSuccess() {
...
}
function onConnectFailure(response) {
WL.Logger.debug(response);
}

MobileFirst and Ionic Push notification callback

I have an Ionic project and I added a push notification callback handler as explained in official documentation (my expectation is to have some alert when inside the app and a notification arrive), but it is never invoked.
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
pushNotificationReceived);
Here the question is where I have to place the pushNotificationReceived function to be called ? I try in index.js and inside the controller as a function, but I do not have success.
Thank for help
Have you reviewed the sample application for push notifications?.
The sample demonstrates implementation of push notifications APIs. https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/event-source-notifications-in-hybrid-applications/
See the supplied main.js file: https://github.com/MobileFirst-Platform-Developer-Center/EventSourceNotifications/blob/release71/apps/HybridEventSource/common/js/main.js
You have to include callback function in ionic inside the app.js file after "Successfully connected with mobile first server".
WLAuthorizationManager.obtainAccessToken().then(
function (response) {
//alert("successfully obtained a token from the server");
MFPPush.initialize (
function(successResponse) {
//alert("Successfully intialized");
MFPPush.registerNotificationsCallback(notificationReceived);
},
function(failureResponse) {
console.log("Failed to initialize");
}
);
MFPPush.isPushSupported (
function(successResponse) {
//alert("Push Supported: " + successResponse);
},
function(failureResponse) {
console.log("Failed to get push support status");
}
);
MFPPush.registerDevice(
function(successResponse) {
//alert("Successfully registered");
},
function(failureResponse) {
console.log("Failed to register");
}
);
function notificationReceived(message) {
alert(JSON.stringify(message.alert));
}
},
function(response) {
//alert("res"+JSON.stringify(response));
console.log("Unable to obtain a token from the server: " + JSON.stringify(response));
if(JSON.stringify(response.status) == 403){
console.log("The Application is disabled on this Device");
ionic.Platform.exitApp();
}
}
);