我已经在我的ionic v4应用中实现了onesignal, 一切在调试测试中都是完美的,但是在Android和ios上投入生产时,我都会出错并停止编译。
ionic cordova build android --prod --release
ionic cordova build ios --prod
在两种情况下,终端显示相同的错误
ERROR in app/app.module.ts(66,5): Error during template compile of 'AppModule'
Function expressions are not supported in decorators in 'OneSignal'
'OneSignal' references 'ɵ2'
'ɵ2' contains the error at ../@ionic-native/onesignal/ngx/index.js.ts(64,32)
Consider changing the function expression into an exported function.
这是@ ionic-native / onesignal / ngx / index.js.ts中的函数代码
var OneSignal = /** @class */ (function (_super) {
__extends(OneSignal, _super);
function OneSignal() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* constants to use in inFocusDisplaying()
* @hidden
*/
_this.OSInFocusDisplayOption = {
None: 0,
InAppAlert: 1,
Notification: 2
};
return _this;
}
OneSignal.prototype.startInit = function (appId, googleProjectNumber) { return cordova(this, "startInit", { "sync": true }, arguments); };
OneSignal.prototype.handleNotificationReceived = function () { return cordova(this, "handleNotificationReceived", { "observable": true }, arguments); };
OneSignal.prototype.handleNotificationOpened = function () { return cordova(this, "handleNotificationOpened", { "observable": true }, arguments); };
OneSignal.prototype.iOSSettings = function (settings) { return cordova(this, "iOSSettings", { "sync": true, "platforms": ["iOS"] }, arguments); };
OneSignal.prototype.endInit = function () { return cordova(this, "endInit", { "sync": true }, arguments); };
OneSignal.prototype.promptForPushNotificationsWithUserResponse = function () { return cordova(this, "promptForPushNotificationsWithUserResponse", { "platforms": ["iOS"] }, arguments); };
OneSignal.prototype.getTags = function () { return cordova(this, "getTags", {}, arguments); };
OneSignal.prototype.getIds = function () { return cordova(this, "getIds", {}, arguments); };
OneSignal.prototype.sendTag = function (key, value) { return cordova(this, "sendTag", { "sync": true }, arguments); };
OneSignal.prototype.sendTags = function (json) { return cordova(this, "sendTags", { "sync": true }, arguments); };
OneSignal.prototype.deleteTag = function (key) { return cordova(this, "deleteTag", { "sync": true }, arguments); };
OneSignal.prototype.deleteTags = function (keys) { return cordova(this, "deleteTags", { "sync": true }, arguments); };
OneSignal.prototype.registerForPushNotifications = function () { return cordova(this, "registerForPushNotifications", { "sync": true }, arguments); };
OneSignal.prototype.enableVibrate = function (enable) { return cordova(this, "enableVibrate", { "sync": true }, arguments); };
OneSignal.prototype.enableSound = function (enable) { return cordova(this, "enableSound", { "sync": true }, arguments); };
OneSignal.prototype.inFocusDisplaying = function (displayOption) { return cordova(this, "inFocusDisplaying", { "sync": true }, arguments); };
OneSignal.prototype.setSubscription = function (enable) { return cordova(this, "setSubscription", { "sync": true }, arguments); };
OneSignal.prototype.getPermissionSubscriptionState = function () { return cordova(this, "getPermissionSubscriptionState", {}, arguments); };
OneSignal.prototype.postNotification = function (notificationObj) { return cordova(this, "postNotification", {}, arguments); };
OneSignal.prototype.cancelNotification = function (notificationId) { return cordova(this, "cancelNotification", { "sync": true }, arguments); };
OneSignal.prototype.promptLocation = function () { return cordova(this, "promptLocation", { "sync": true }, arguments); };
OneSignal.prototype.syncHashedEmail = function (email) { return cordova(this, "syncHashedEmail", { "sync": true }, arguments); };
OneSignal.prototype.setLogLevel = function (logLevel) { return cordova(this, "setLogLevel", { "sync": true }, arguments); };
OneSignal.prototype.setLocationShared = function (shared) { return cordova(this, "setLocationShared", { "sync": true }, arguments); };
OneSignal.prototype.addPermissionObserver = function () { return cordova(this, "addPermissionObserver", { "observable": true }, arguments); };
OneSignal.prototype.addSubscriptionObserver = function () { return cordova(this, "addSubscriptionObserver", { "observable": true }, arguments); };
OneSignal.prototype.setEmail = function (email, emailAuthToken) { return cordova(this, "setEmail", {}, arguments); };
OneSignal.prototype.logoutEmail = function () { return cordova(this, "logoutEmail", {}, arguments); };
OneSignal.prototype.addEmailSubscriptionObserver = function () { return cordova(this, "addEmailSubscriptionObserver", { "observable": true }, arguments); };
OneSignal.prototype.clearOneSignalNotifications = function () { return cordova(this, "clearOneSignalNotifications", { "sync": true }, arguments); };
OneSignal.prototype.setRequiresUserPrivacyConsent = function (required) { return cordova(this, "setRequiresUserPrivacyConsent", {}, arguments); };
OneSignal.prototype.provideUserConsent = function (granted) { return cordova(this, "provideUserConsent", {}, arguments); };
OneSignal.prototype.userProvidedPrivacyConsent = function (callback) { return cordova(this, "userProvidedPrivacyConsent", {}, arguments); };
OneSignal.pluginName = "OneSignal";
OneSignal.plugin = "onesignal-cordova-plugin";
OneSignal.pluginRef = "plugins.OneSignal";
OneSignal.repo = "https://github.com/OneSignal/OneSignal-Cordova-SDK";
OneSignal.platforms = ["Amazon Fire OS", "Android", "iOS", "Windows"];
OneSignal = __decorate([
Injectable()
], OneSignal);
return OneSignal;
}(IonicNativePlugin));
这是我的环境
Ionic:
ionic (Ionic CLI) : 4.10.3 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.0
@angular-devkit/build-angular : 0.12.3
@angular-devkit/schematics : 7.2.3
@angular/cli : 7.2.3
@ionic/angular-toolkit : 1.2.2
Capacitor:
capacitor (Capacitor CLI) : 1.0.0-beta.17
@capacitor/core : 1.0.0-beta.11
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : not available
Cordova Plugins : not available
System:
ios-deploy : 1.9.4
NodeJS : v8.11.3 (/usr/local/bin/node)
npm : 6.8.0
OS : macOS High Sierra
Xcode : Xcode 10.1 Build version 10B61
答案 0 :(得分:0)
我发布了答案,因为我已经修复了错误。
标志--prod
最小化和优化了项目,包括提高性能的AoT(提前)。是AoT导致与OneSignal插件发生冲突。
解决方案是不使用--prod
,而仅使用标志--release
进行编译。
我正在调查是否有可能使用--prod排除AoT,但是至少到目前为止,这是一个很好的解决方案,另一方面,我的应用程序运行非常快。