Ionic3 - 本地通知结束?
Ionic3 - the end of local notifications?
为戏剧性的标题道歉,但我对离子和本地通知有很多挫败感。
我使用 ionic 2 构建了一个应用程序,该应用程序使用本地通知。
我已升级到 ionic3 并尝试了所有方法,但无法使本地通知正常工作。
最新版本的本地通知不支持ionic所以我不得不使用更早的版本0.8.4或0.8.5。
但是尝试安装这些版本会引发错误。我已经尝试了一切,包括启动一个干净的 ionic3 项目和安装本地通知。 (例如,我尝试遵循此 http://masteringionic.com/blog/2018-01-09-adding-local-notifications-to-an-ionic-framework-mobile-app/)
没有任何效果。不确定我们如何在没有本地通知的情况下将 Ionic 用作生产框架?
有没有人让这个工作或有任何建议?
谢谢
更新:
最近甚至只是尝试安装本地通知都失败了
Failed to install 'de.appplant.cordova.plugin.local-notification':
CordovaError: Failed to fetch plugin cordova-plugin-app-event via
registry
更新:
我取得了一点进步。
我又玩了一些,决定看看我拥有的另一个使用本地通知的旧离子项目。
它使用特定版本的本地通知,所以我去安装了那个特定版本。
npm install @ionic-native/local-notifications@3.12.1
完成后我可以 运行 ionic build 并且没有失败就完成了!!好消息!。
坏消息 - 当我 运行 ionic serve 它启动应用程序但出现白屏和控制台错误:我收到一条错误消息
polyfills.js:3 Unhandled Promise rejection: No provider for LocalNotifications! ; Zone: ; Task: Promise.then ; Value: Error: No provider for LocalNotifications!
即使我已经将它添加到我的应用程序模块中的提供商列表中。
当我尝试 运行 构建 android 时,出现以下错误。我正式没主意了。有帮助吗???
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;
BUILD FAILED
Total time: 29.376 secs
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
Execution failed for task ':transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;
在 Package.json 我升级了
"@ionic-native/local-notifications": "^5.5.1"
现在正在工作。
我做到了
$npm i -g npm-check-updates
$npm-check-updates -u
$npm install
但是升级所有东西都丢失了错误。
所以我从 package.json 和 package-lock.json
回滚了
然后决定只在package.json
手动更改
"@ionic-native/local-notifications": "^5.5.1"
然后做了:
$npm install
注意:
$npm-check-updates -u.
给了我一个这样的列表:
@angular/common ^7.2.2 → ^7.2.14
@angular/core ^7.2.2 → ^7.2.14
@angular/forms ^7.2.2 → ^7.2.14
@angular/http ^7.2.2 → ^7.2.14
@angular/platform-browser ^7.2.2 → ^7.2.14
@angular/platform-browser-dynamic ^7.2.2 → ^7.2.14
@angular/router ^7.2.2 → ^7.2.14
@angular/service-worker ^7.2.8 → ^7.2.14
@ionic-native/camera ^5.2.0 → ^5.5.1
@ionic-native/core ^5.0.0 → ^5.5.1
@ionic-native/device ^5.3.0 → ^5.5.1
@ionic-native/file ^5.2.0 → ^5.5.1
@ionic-native/file-path ^5.2.0 → ^5.5.1
@ionic-native/ionic-webview ^5.2.0 → ^5.5.1
@ionic-native/local-notifications ^5.2.0 → ^5.5.1
@ionic-native/native-audio ^5.2.0 → ^5.5.1
@ionic-native/network ^5.2.0 → ^5.5.1
@ionic-native/power-management ^5.4.0 → ^5.5.1
@ionic-native/splash-screen ^5.0.0 → ^5.5.1
@ionic-native/status-bar ^5.0.0 → ^5.5.1
@ionic/angular ^4.1.0 → ^4.3.1
cordova-android 7.1.4 → 8.0.0
cordova-android-support-gradle-release ^2.0.1 → ^3.0.0
cordova-plugin-filepath 1.5.1 → 1.5.4
cordova-plugin-ionic-webview ^3.1.2 → ^4.0.1
cordova-sqlite-storage 3.1.0 → 3.2.0
core-js ^2.5.4 → ^3.0.1
ionic-selectable ^4.4.0 → ^4.4.1
rxjs ~6.3.3 → ~6.5.1
zone.js ~0.8.29 → ~0.9.1
@angular-devkit/architect ~0.12.3 → ~0.13.8
@angular-devkit/build-angular ~0.13.0 → ~0.13.8
@angular-devkit/core ~7.2.3 → ~7.3.8
@angular-devkit/schematics ~7.2.3 → ~7.3.8
@angular/cli ~7.3.1 → ~7.3.8
@angular/compiler ~7.2.2 → ~7.2.14
@angular/compiler-cli ~7.2.2 → ~7.2.14
@angular/language-service ~7.2.2 → ~7.2.14
@ionic/angular-toolkit ~1.4.0 → ~1.5.1
@types/jasmine ~2.8.8 → ~3.3.12
@types/jasminewd2 ~2.0.3 → ~2.0.6
@types/node ~10.12.0 → ~12.0.0
codelyzer ~4.5.0 → ~5.0.1
jasmine-core ~2.99.1 → ~3.4.0
karma ~3.1.4 → ~4.1.0
karma-coverage-istanbul-reporter ~2.0.1 → ~2.0.5
karma-jasmine ~1.1.2 → ~2.0.1
karma-jasmine-html-reporter ^0.2.2 → ^1.4.2
protractor ~5.4.0 → ~5.4.2
ts-node ~8.0.0 → ~8.1.0
tslint ~5.12.0 → ~5.16.0
typescript ~3.1.6 → ~3.4.5
所以我可以决定升级什么
最后我只好直接使用Cordova插件,没有使用ionic native层。结果,我能够使用 local-notifications 的一个分支,它到目前为止在所有设备上都运行良好 - android 和 ios.
我只是根据 packages.json
添加了这个 Cordova 插件
"cordova-plugin-local-notification":
"git+https://github.com/Steffaan/cordova-plugin-local-notifications.git",
然后我的代码看起来像这样...
import {Platform} from 'ionic-angular';
import { environment } from '../../environments/environment.prod';
declare var cordova;
@Injectable()
export class Notifications {
localNotifications: any;
constructor(public storage: Storage, public platform: Platform, public settings: Settings) {
this.localNotifications = cordova.plugins.notification.local;
}
getAllNotifications(): Promise<any[]> {
return new Promise(resolve => {
this.localNotifications.getAll(resolve);
});
}
etc...
为戏剧性的标题道歉,但我对离子和本地通知有很多挫败感。 我使用 ionic 2 构建了一个应用程序,该应用程序使用本地通知。 我已升级到 ionic3 并尝试了所有方法,但无法使本地通知正常工作。
最新版本的本地通知不支持ionic所以我不得不使用更早的版本0.8.4或0.8.5。 但是尝试安装这些版本会引发错误。我已经尝试了一切,包括启动一个干净的 ionic3 项目和安装本地通知。 (例如,我尝试遵循此 http://masteringionic.com/blog/2018-01-09-adding-local-notifications-to-an-ionic-framework-mobile-app/)
没有任何效果。不确定我们如何在没有本地通知的情况下将 Ionic 用作生产框架?
有没有人让这个工作或有任何建议?
谢谢
更新: 最近甚至只是尝试安装本地通知都失败了
Failed to install 'de.appplant.cordova.plugin.local-notification': CordovaError: Failed to fetch plugin cordova-plugin-app-event via registry
更新: 我取得了一点进步。 我又玩了一些,决定看看我拥有的另一个使用本地通知的旧离子项目。 它使用特定版本的本地通知,所以我去安装了那个特定版本。
npm install @ionic-native/local-notifications@3.12.1
完成后我可以 运行 ionic build 并且没有失败就完成了!!好消息!。 坏消息 - 当我 运行 ionic serve 它启动应用程序但出现白屏和控制台错误:我收到一条错误消息
polyfills.js:3 Unhandled Promise rejection: No provider for LocalNotifications! ; Zone: ; Task: Promise.then ; Value: Error: No provider for LocalNotifications!
即使我已经将它添加到我的应用程序模块中的提供商列表中。
当我尝试 运行 构建 android 时,出现以下错误。我正式没主意了。有帮助吗???
FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper; BUILD FAILED Total time: 29.376 secs Error: cmd: Command failed with exit code 1 Error output: FAILURE: Build failed with an exception. Execution failed for task ':transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;
在 Package.json 我升级了
"@ionic-native/local-notifications": "^5.5.1"
现在正在工作。
我做到了
$npm i -g npm-check-updates
$npm-check-updates -u
$npm install
但是升级所有东西都丢失了错误。 所以我从 package.json 和 package-lock.json
回滚了然后决定只在package.json
手动更改"@ionic-native/local-notifications": "^5.5.1"
然后做了:
$npm install
注意:
$npm-check-updates -u.
给了我一个这样的列表:
@angular/common ^7.2.2 → ^7.2.14
@angular/core ^7.2.2 → ^7.2.14
@angular/forms ^7.2.2 → ^7.2.14
@angular/http ^7.2.2 → ^7.2.14
@angular/platform-browser ^7.2.2 → ^7.2.14
@angular/platform-browser-dynamic ^7.2.2 → ^7.2.14
@angular/router ^7.2.2 → ^7.2.14
@angular/service-worker ^7.2.8 → ^7.2.14
@ionic-native/camera ^5.2.0 → ^5.5.1
@ionic-native/core ^5.0.0 → ^5.5.1
@ionic-native/device ^5.3.0 → ^5.5.1
@ionic-native/file ^5.2.0 → ^5.5.1
@ionic-native/file-path ^5.2.0 → ^5.5.1
@ionic-native/ionic-webview ^5.2.0 → ^5.5.1
@ionic-native/local-notifications ^5.2.0 → ^5.5.1
@ionic-native/native-audio ^5.2.0 → ^5.5.1
@ionic-native/network ^5.2.0 → ^5.5.1
@ionic-native/power-management ^5.4.0 → ^5.5.1
@ionic-native/splash-screen ^5.0.0 → ^5.5.1
@ionic-native/status-bar ^5.0.0 → ^5.5.1
@ionic/angular ^4.1.0 → ^4.3.1
cordova-android 7.1.4 → 8.0.0
cordova-android-support-gradle-release ^2.0.1 → ^3.0.0
cordova-plugin-filepath 1.5.1 → 1.5.4
cordova-plugin-ionic-webview ^3.1.2 → ^4.0.1
cordova-sqlite-storage 3.1.0 → 3.2.0
core-js ^2.5.4 → ^3.0.1
ionic-selectable ^4.4.0 → ^4.4.1
rxjs ~6.3.3 → ~6.5.1
zone.js ~0.8.29 → ~0.9.1
@angular-devkit/architect ~0.12.3 → ~0.13.8
@angular-devkit/build-angular ~0.13.0 → ~0.13.8
@angular-devkit/core ~7.2.3 → ~7.3.8
@angular-devkit/schematics ~7.2.3 → ~7.3.8
@angular/cli ~7.3.1 → ~7.3.8
@angular/compiler ~7.2.2 → ~7.2.14
@angular/compiler-cli ~7.2.2 → ~7.2.14
@angular/language-service ~7.2.2 → ~7.2.14
@ionic/angular-toolkit ~1.4.0 → ~1.5.1
@types/jasmine ~2.8.8 → ~3.3.12
@types/jasminewd2 ~2.0.3 → ~2.0.6
@types/node ~10.12.0 → ~12.0.0
codelyzer ~4.5.0 → ~5.0.1
jasmine-core ~2.99.1 → ~3.4.0
karma ~3.1.4 → ~4.1.0
karma-coverage-istanbul-reporter ~2.0.1 → ~2.0.5
karma-jasmine ~1.1.2 → ~2.0.1
karma-jasmine-html-reporter ^0.2.2 → ^1.4.2
protractor ~5.4.0 → ~5.4.2
ts-node ~8.0.0 → ~8.1.0
tslint ~5.12.0 → ~5.16.0
typescript ~3.1.6 → ~3.4.5
所以我可以决定升级什么
最后我只好直接使用Cordova插件,没有使用ionic native层。结果,我能够使用 local-notifications 的一个分支,它到目前为止在所有设备上都运行良好 - android 和 ios.
我只是根据 packages.json
添加了这个 Cordova 插件"cordova-plugin-local-notification": "git+https://github.com/Steffaan/cordova-plugin-local-notifications.git",
然后我的代码看起来像这样...
import {Platform} from 'ionic-angular';
import { environment } from '../../environments/environment.prod';
declare var cordova;
@Injectable()
export class Notifications {
localNotifications: any;
constructor(public storage: Storage, public platform: Platform, public settings: Settings) {
this.localNotifications = cordova.plugins.notification.local;
}
getAllNotifications(): Promise<any[]> {
return new Promise(resolve => {
this.localNotifications.getAll(resolve);
});
}
etc...