我尝试在我的Nativescript(angular with typescript)项目中使用PushWoosh SDK(http://docs.pushwoosh.com/docs/native-ios-sdk)。 因此我做了以下事情:
在设备上运行的结果:
似乎一切都很好,但是没有调用注册回调,如果我尝试调用" getPushToken" in" applicationDidBecomeActive"它是空的,正如我所说 - 没有"推动启用" Pushwoosh门户网站中的设备。
AppDelegate.ios.ts:
import * as application from "application";
import "@zapsod/ns-pushwoosh" // My PW Plugin
import { ios } from "application";
import {platformCommon} from "./platform-common"
declare var PushNotificationManager;
declare var PushNotificationDelegate;
declare interface PushNotificationDelegate{
onPushAccepted(pushManager, withNotification, onStart);
didRegisterForRemoteNotificationsWithDeviceToken(deviceToken);
didFailToRegisterForRemoteNotificationsWithError(error);
didReceiveRemoteNotification(userInfo, completionHandler);
}
var pushManager =PushNotificationManager.pushManager();
//var PushNotificationManager = <any>pw.PushNotificationManager;
export class MyDelegate extends UIResponder implements
UIApplicationDelegate, PushNotificationDelegate{
public static ObjCProtocols = [UIApplicationDelegate,
PushNotificationDelegate];
applicationDidFinishLaunchingWithOptions(application: UIApplication,
launchOptions): boolean {
console.profile();
console.log("applicationWillFinishLaunchingWithOptions: ", this)
pushManager.delegate = this;
UNUserNotificationCenter.currentNotificationCenter().delegate =
pushManager.notificationCenterDelegate;
pushManager.sendAppOpen();
console.log(application.currentUserNotificationSettings);
pushManager.registerForPushNotifications();
return true;
}
applicationDidBecomeActive(application: UIApplication): void {
console.log("applicationDidBecomeActive: " + application)
console.log("is registered",
application.registeredForRemoteNotifications)
}
onPushAccepted(pushManager, withNotification, onStart){
console.log("pushaccepted", withNotification)
}
didRegisterForRemoteNotificationsWithDeviceToken(deviceToken) {
console.info("registered for pushed token ", platformCommon)
platformCommon.pushToken = deviceToken;
pushManager.handlePushRegistration(deviceToken);
}
didFailToRegisterForRemoteNotificationsWithError(error){
console.error("failed to register push ", error)
pushManager.handlePushRegistrationFailure(error)
}
didReceiveRemoteNotification(userInfo, completionHandler){
pushManager.handlePushReceived(userInfo);
completionHandler(UIBackgroundFetchResult.NoData);
}
}
application.ios.delegate = MyDelegate;