如何在 iOS 的 Nativescript 中实现一个信号

how to implement One signal in Nativescript for iOS

我正在尝试在 Nativescript 中实现 One Signal。为此,我使用 nativescript-onesignal plugin。它适用于 android 但不适用于 iOS。我在 Sidekick 控制台中给出了这些错误:

ERROR: Encountered error during push registration with OneSignal: Error Domain=OneSignal Error Code=403 "(null)" UserInfo={returned=Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}}
ERROR: Encountered error during email registration with OneSignal: (null)

只要存在这些错误,One Signal 就无法将我的设备检测为订阅者。 有人知道如何为 iOS 实现吗? 我不知道该如何解决。有什么想法吗?

这是我的 main.ts 文件:

// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { platformNativeScriptDynamic } from "nativescript-angular/platform";

import { AppModule } from "./app/app.module";

import * as application from "tns-core-modules/application";
const TnsOneSignal = require("nativescript-onesignal").TnsOneSignal;
// A traditional NativeScript application starts by initializing global objects, setting up global CSS rules, creating, and navigating to the main page. 
// Angular applications need to take care of their own initialization: modules, components, directives, routes, DI providers. 
// A NativeScript Angular app needs to make both paradigms work together, so we provide a wrapper platform object, platformNativeScriptDynamic, 
// that sets up a NativeScript application and can bootstrap the Angular framework.

console.log("main starts");

if (application.ios) {
    class MyDelegate extends UIResponder implements UIApplicationDelegate {

        public static ObjCProtocols = [UIApplicationDelegate];

        public applicationDidFinishLaunchingWithOptions(app: UIApplication, launchOptions: NSDictionary<any, any>): boolean {

            try {

                console.log("TnsOneSignal", TnsOneSignal);
                // init to recieve push notification
                TnsOneSignal.initWithLaunchOptionsAppId(launchOptions, "b2fdda95*********");

                // I have not yet implemented the part of receiving notifications in ios, when I have it I will publish it

            } catch (error) {
                console.log("TnsOneSignal error", error);
            }

            return true;
        }

    }
    application.ios.delegate = MyDelegate;
}

if (application.android) {
    application.on(application.launchEvent, function(args: application.ApplicationEventData) {

        try {

            console.log("TnsOneSignal", TnsOneSignal);
            TnsOneSignal.ini(application.android.context).init()

        } catch (error) {
            console.error("error", error)
        }

    });
}

platformNativeScriptDynamic().bootstrapModule(AppModule);

折腾了几天,终于找到问题所在了!它已通过使用 VPN 修复。