如何避免Cordova插件阻塞Ionic 3中的主线程

时间:2018-10-06 21:19:40

标签: cordova ionic3 cordova-plugins

我是Ionic的新人。我正在使用cordova-sms-plugin。每当我调用此插件时,都会收到消息

type FieldMap<SRC> = {
    [ATTR in keyof SRC]?: (value: SRC[ATTR], obj: SRC) => any
};
type ComputedMap<SRC> = {
    [ATTR in keyof SRC]?: never
} & {
    [ATTR: string]: (value: undefined, obj: SRC) => any
};
type MappedReturnType<SRC, FM extends FieldMap<SRC>, CM extends ComputedMap<SRC>> = {
    [ATTR in keyof CM]: ReturnType<CM[ATTR]>
} & {
    [ATTR in keyof SRC]: ATTR extends keyof FM
        ? FM[ATTR] extends (value: SRC[ATTR], obj: SRC) => infer R ? R : SRC[ATTR]
        : SRC[ATTR]
}

export function mapJson<
    SRC extends object, FM extends FieldMap<SRC>, CM extends ComputedMap<SRC>
>(src: SRC, fieldMap: FM, computedMap: CM): MappedReturnType<SRC, FM, CM> {
    // impl .. not the point of the question
    return undefined!;
}

let mappedResult = mapJson(
    { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" },
    // Without `: number`, `ts` is inferred as any:
    // probably https://github.com/Microsoft/TypeScript/issues/24694.
    { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape},
    {computed: (_, obj) => `${obj?`${obj.aString}__${obj.idempotentValue}`:''}` }
);

let v1 = mappedResult.date; // number, expected
let v2 = mappedResult.date2; // Date, expected
let v3 = mappedResult.aString; // string, expected
let v4 = mappedResult.idempotentValue; // string, expected
let v5 = mappedResult.computed; // string, expected

作为示例,我的代码如下:

W/PluginManager: THREAD WARNING: exec() call to SMS.listSMS blocked the main thread for 34ms. Plugin should use CordovaInterface.getThreadPool().

我的假设是,如果this.platform()。ready()则它自己处理线程,但是它很幼稚。有没有一种方法可以管理线程以避免阻塞主线程?

另一个问题是,经过几次短信检查后,我的应用程序冻结了。

0 个答案:

没有答案