Closed EbrahimTahernejad closed 7 years ago
You can bypass these TypeScript errors by setting "noEmitOnError": false
thanks
now
https.request({
url: 'http://site.com/api/?action=latest_chapters&format=json',
method: 'GET',
headers: {
//'Authorization': 'Basic ZWx1c3VhcmlvOnlsYWNsYXZl',
},
}).then(response => {
console.log(response.content.toString())
}).catch(error => {
console.log(error);
});
results:
JS: Error: android.os.NetworkOnMainThreadException
JS: android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
JS: libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:249)
JS: libcore.io.IoBridge.recvfrom(IoBridge.java:553)
JS: java.net.PlainSocketImpl.read(PlainSocketImpl.java:485)
JS: java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
JS: java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
JS: okio.Okio$2.read(Okio.java:138)
JS: okio.AsyncTimeout$2.read(AsyncTimeout.java:236)
JS: okio.RealBufferedSource.indexOf(RealBufferedSource.java:325)
JS: okio.RealBufferedSource.indexOf(RealBufferedSource.java:314)
JS: okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:210)
JS: okhttp3.internal.http1.Http1Codec$ChunkedSource.readChunkSize(Http1Codec.java:442)
JS: okhttp3.internal.http1.Http1Codec$ChunkedSource.read(Http1Codec.java:426)
JS: okhttp3.internal.Util.skipAll(Util.java:165)
JS: okhttp3.internal.Util.discard(Util.java:147)
JS: okhttp3.internal.http1.Http1Codec$ChunkedSource.close(Http1Codec.java:463)
JS: okio.RealBufferedSource.close(RealBufferedSource.java:434)
JS: okio.RealBufferedSource.close(RealBufferedSource.java:434)
JS: okio.InflaterSource.close(InflaterSource.java:126)
JS: okio.GzipSource.close(GzipSource.java:182)
JS: okio.RealBufferedSource.close(RealBufferedSource.java:434)
JS: okhttp3.internal.Util.closeQuietly(Util.java:100)
JS: okhttp3.ResponseBody.string(ResponseBody.java:176)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.access$2400(Runtime.java:33)
JS: com.tns.Runtime$3.run(Runtime.java:1054)
JS: android.os.Handler.handleCallback(Handler.java:739)
JS: android.os.Handler.dispatchMessage(Handler.java:95)
JS: android.os.Looper.loop(Looper.java:145)
JS: android.app.ActivityThread.main(ActivityThread.java:5832)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
@AOTOA You'll want to add this somewhere:
application.android.on(application.AndroidApplication.activityCreatedEvent, function(args: application.AndroidActivityBundleEventData) {
let policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll().build()
android.os.StrictMode.setThreadPolicy(policy)
})
thanks It did the work 💃
import * as application from 'application';
The snippet also solved my problem. However (for the benefit of others who stumble here as I did and might get tripped up), the non-Typescript Javascript version is more like this:
if(application.android) {
application.android.on(application.AndroidApplication.activityCreatedEvent, function () {
let policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll().build()
android.os.StrictMode.setThreadPolicy(policy)
})
}
@roblav96 : Don't you think this bit of preamble should be resident in the plugin or alternately update the plugin to wrap the business within AsyncTask, rather than putting this burden on the {N} developer?
I tried to compile the latest NS with this plugin and here is what it told me
my refrences.d.ts
my tsconfig