tarang shah
tarang shah

Reputation: 1

Using tns preview or tns preview --bundle axios on mobile doesn't work

I try to connect my api with nativescript when i run in android emulator axios get all data from backend but when i try to run on actual mobile using tns preview or tns preview --bundle axios not working its give me null value

LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(Page)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(Page(3), ActionBar(4))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(ActionBar)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(gridlayout)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(Frame)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(stacklayout)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(textfield)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(6), Label(7))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(label)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(stacklayout)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(8), TextField(9))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(button)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(8), Button(10))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(6), StackLayout(8))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(GridLayout(5), StackLayout(6))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateComment()
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(ListView)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(Page(3), GridLayout(5))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(ListView(11), Placeholder(13))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(GridLayout(5), ListView(11))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(Frame(2), Page(3))
**LOG from device Tarang shah: null**

Any one know how to solve this issue and my backend api store on serve not in local device

My code for axios

axios({ method: "GET", "url": "http://api.sinhgadcollegeofscience.com/api/todos" }).then(result => {
                console.log(result.data)
                commit('setTodos', result.data)
            }, error => {       
                console.log('errorsssss')
            });

Upvotes: 0

Views: 80

Answers (1)

Igor R.
Igor R.

Reputation: 897

You are making a clearText request (http://...) which is disabled by default since android API 28 I believe.

If you can, try using a https connection. Otherwise you can enable clearText traffic in the AndroidManifest.xml

<application
 <!-- ... -->
 android:usesCleartextTraffic="true"
 <!-- ... -->
</application>

After making the change, delete the platforms folder, and rebuild the app.

More detailed information can be found here: Android 8: Cleartext HTTP traffic not permitted

Upvotes: 1

Related Questions