roblav96 / nativescript-onesignal

A Nativescript plugin that wraps the iOS and Android OneSignal Push Notifications SDK.
https://documentation.onesignal.com/docs/getting-started
Other
24 stars 42 forks source link

can't register although app starts on iOS #53

Closed meysam-mahmoodi closed 5 years ago

meysam-mahmoodi commented 5 years ago

Hello I get errors on iOS while my app is going to start. everything is ok on Android. my main.ts file is:

// 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-e2aa-494f-9873-ca8b92a1d43b");

                // 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);

errors:

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)

what can I do to solve the problem? anybody could install the plugin and implement it on iOS?

meysam-mahmoodi commented 5 years ago

After some days, Finally, I found what the problem was! it was fixed by using a VPN.