Ionic 2 mobilefirst 8.0 adapter call not working in browser - ibm-mobilefirst

I am invoking a procedure on mobilefirst 8.0 adapter from ionic 2
I am able to see the response in device but not in chrome.Got the below error
ReferenceError: WLResourceRequest is not defined.Below is my code
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { TransitPage } from '../transit/transit';
import { TrackDartPage } from '../track-dart/track-dart';
import { LocationFinderPage } from '../location-finder/location-finder';
import {Http} from '#angular/http';
import 'rxjs/add/operator/map';
declare var WLResourceRequest;
calladapter(){
var resourceRequest = new WLResourceRequest("/adapters/trackDart/status/" + 2,WLResourceRequest.GET);
resourceRequest.send().then((response) => {
alert(JSON.stringify(response.responseText));
},
function(error){
alert(JSON.stringify(error));
});
}

By the error I suspect that you are running ionic serve which is leading you to this error since ionic does not know about MobileFirst. Instead, run mfpdev app preview after running npm run watch command.

Related

react native Android Cannot access realm that has been closed

im using Realm inside my React native app, in IOS everything work fine, but with Android I always got this error: Cannot access realm that has been closed
here is my Realm:
RealmContext.js
import { ContactInfo, Room, RoomBackground, RoomDetail, RoomMessage, Summary } from "../database/RealmSchemas"
import { Realm, createRealmContext } from '#realm/react'
const config = {
schema: [Room.schema,
ContactInfo.schema,
RoomDetail.schema,
RoomBackground.schema,
Summary.schema,
RoomMessage.schema],
}
export default createRealmContext(config)
Other class
import RealmContext from '../../context/RealmContext'
const { useRealm, useQuery } = RealmContext
export class....{
const realm = useRealm()
const getRoomDetailFromDb = () => {
try {
const roomDetailDb = realm.objectForPrimaryKey('RoomDetail', room.RoomId)
if (roomDetailDb != null) {
roomDetail = JSON.parse(roomDetailDb.value)
}
} catch (error) {
console.log(error)
}
}
here is my version of realm:
"realm": "^10.18.0",
"#realm/react": "^0.3.0",
i did following the site: https://www.mongodb.com/docs/realm/sdk/react-native/use-realm-react/
Seems like react-native-reanimated lib is not compatible with Realm v10 on Android.
In case you use that please try realm#11.0.0-rc.0. It works fine after I upgrade realm version to v11. Even though it's not a stable version.

Using react native module (with native code) in expo project

I am working in an existing expo project (expo version 42.0.1 ) and I am unable to get this package working. It says in the package readme that it doesn't work with Expo, because it uses native code. But the readme is from a year ago and I thought Expo sdk42 allows you to use native modules now when you build your own custom client?
Does anyone know what I need to do to get this package working?
https://github.com/KjellConnelly/react-native-shared-group-preferences
Here's what i tried so far...
I added to my project with yarn add react-native-shared-group-preferences
And in App.js :
import 'expo-dev-client';
import React from 'react';
import { styles } from './src/components/CommonStyles';
import { useState } from 'react';
import { View, TextInput, Text } from 'react-native';
import SharedGroupPreferences from 'react-native-shared-group-preferences';
export default function App() {
const [inputText, setInputText] = useState('');
const widgetData = {
displayText: inputText,
};
const appGroupIdentifier = 'group.com.myproject.newwidget';
const handleSubmit = async () => {
try {
console.log('handleSubmit' + widgetData + appGroupIdentifier);
await SharedGroupPreferences.setItem(
'savedData', // this is a key to pull from later in Swift
widgetData,
appGroupIdentifier
);
} catch (error) {
console.log({ error });
}
};
return (
...
)
when I run the project with expo start and i to open iphone simulator,
I get this error: null is not an object (evaluating 'RNReactNativeSharedGroupPreferences.setItem')"
What am I doing wrong? Any help very much appreciated. Thanks

java.lang.String - facebook ad

I am using facebook ads. I wanted to put native ad to my react native expo app, but i got error. When i put simple banner all is ok. It gives me this error:
Uncaught Error: java.lang.String cannot be cast to java.lang.Double
I tried to import like this:
import * as FacebookAds from 'expo-ads-facebook';
but it gave me this error:
Unable to resolve "#unimodules/core" from "node_modules/expo-ads-facebook/build/withNativeAd.js"
What am i doing wrong?
// pageScreen.js
import React from 'react';
import { FacebookAds } from 'expo'
import AdScreenFacebook from './AdScreenFacebook'
class AdScreen extends React.Component {
render () {
return (
<AdScreenFacebook adsManager={adsManager} adChoicePosition="topLeft" expandable={false} />
);
}
}
// AdScreenFacebook.js
import React from 'react';
import { FacebookAds } from 'expo'
const { AdIconView, AdMediaView } = FacebookAds;
const adsManager = new FacebookAds.NativeAdsManager("2272791379702600_2272795453035526", "1");
class AdScreenFacebook extends React.Component {
render () {
return (
<View>
<AdMediaView />
<AdTriggerView>
<Text>{this.props.nativeAd.bodyText}</Text>
</AdTriggerView>
</View>
);
}
}
export default FacebookAds.withNativeAd(AdScreenFacebook);
export default createStackNavigator(
{
Main: {
screen: AdScreen,
},
AdScreenFacebook: {
screen: AdScreenFacebook,
}
},
{
initialRouteName: 'Main',
}
);
Remove the quotation marks from the number 1 in the NativeAdsManager function. You are currently passing that function the number 1 as a string instead of as a number.
// AdScreenFacebook.js
const adsManager = new FacebookAds.NativeAdsManager("2272791379702600_2272795453035526", 1);
With SDK 33, we’re deprecating imports of most modules from the expo package. This means that in a future release, you won’t be able to write, for example, import { FacebookAds } from 'expo';. Rather, you’ll need to install the individual packages for each module you use and import from them instead.
You can use the new expo install command to install modules; this command is a wrapper around npm install/yarn add that automatically installs a module version compatible with your SDK version. For example, for the FacebookAds module, you would run expo install expo-ads-facebook and then use import * as FacebookAds from 'expo-ads-facebook';. This change paves the way for tree-shaking and smaller JavaScript bundles. It also makes moving between the managed and bare workflows simpler.
If you want to use a Expo module such as a question, install it and set it up.
For managed apps, you'll need to run expo install expo-ads-facebook. To use it in a bare React Native app, follow its installation instructions.
Usage
import * as FacebookAds from 'expo-ads-facebook';
const { AdTriggerView, AdMediaView } = FacebookAds;
class AdComponent extends React.Component {
render() {
return (
<View>
<AdMediaView />
<AdTriggerView>
<Text>{this.props.nativeAd.bodyText}</Text>
</AdTriggerView>
</View>
);
}
}
export default FacebookAds.withNativeAd(AdComponent);

TypeError: (0 , _react.useMemo) is not a function - react-native redux

I have got this error and couldnt handle this.
Error is come up here. but I dont know why.
import React, { Component } from 'react';
import { connect } from 'react-redux';
class LibraryList extends Component {
render() {
return null;
}
}
const mapStateToProps = state => ({
});
export default connect(mapStateToProps)(LibraryList);
EDİTED:
I solved this issue with these :
link1
link2
I also came across this problem yesterday too, the issue is to do with the connect function react-redux, I tried an older version of redux and it worked.
Try, npm install react-redux#6.0.0
Try below code:
import React, { Component } from 'react';
import { connect } from 'react-redux';
class LibraryList extends Component {
render() {
return null;
}
}
const mapStateToProps = state => {
return {
}
};
export default connect(mapStateToProps,null)(LibraryList);
Upgrading react-native, react and cleaning xCode worked for me:
$ yarn upgrade react-native#0.59
$ yarn upgrade react#16.8 .
$ rm -rf node_modules
And cmd + shift + k in xCode
React documentation

Ktor QUICK START HTTP API - ERROR Application - Unhandled: GET - /snippets

i'm new to Ktor and i am currently using the quick start http api but i receive the error:
ERROR Application - Unhandled: GET - /snippets
com.fasterxml.jackson.databind.JsonMappingException: kotlin.reflect.jvm.internal.KClassImpl cannot be cast to kotlin.reflect.jvm.internal.KClassImpl (through reference chain: java.util.Collections$Singleton
Map["snippets"]->java.util.ArrayList[0])
CODE:
import com.fasterxml.jackson.databind.SerializationFeature
import io.ktor.application.*
import io.ktor.features.CallLogging
import io.ktor.features.ContentNegotiation
import io.ktor.features.DefaultHeaders
import io.ktor.jackson.jackson
import io.ktor.request.receive
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.Routing
import io.ktor.routing.get
import io.ktor.routing.post
import io.ktor.routing.routing
import java.util.*
data class Snippet(val text: String)
val snippets = Collections.synchronizedList(mutableListOf(
Snippet("hello"),
Snippet("world")
))
fun Application.main() {
install(ContentNegotiation) {
jackson {
enable(SerializationFeature.INDENT_OUTPUT)
}
}
routing {
get("/snippets") {
call.respond(mapOf("snippets" to synchronized(snippets) { snippets.toList() }))
}
}
}
If i use this instead:
call.respond(mapOf("snippets" to synchronized(snippets) { snippets.toString() }))
it returns:
{
"snippets" : "[Snippet(text=hello), Snippet(text=world)]"
}
but now it's using toString() rather than toList(), any idea how i can get it to work as in the quick start using toList()?
Found the issue.
using the watch option in the application.conf file to run the server seems to mess a couple things up.
application.conf file:
ktor {
deployment {
port = 8080
watch = [ / ]
}
application {
modules = [ com.MainKt.main ]
}
}
removing
watch = [ / ]
or switching back to the embedded server seems to have fixed the issue.
fun main() {
embeddedServer(Netty, 8080) {
//rest of the code
}.start(wait = true)
}