译者注

优质
小牛编辑
112浏览
2023-12-01

译者于2017-5-2日看完全书,基本跑通所有代码,除IBM PouchDB部分外。

译者的 ionic info 如下:

  1. cordova cli:6.5.0
  2. Ionic CLI Version:2.2.3
  3. Ionic App Lib Version:2.2.1
  4. os:Windows 7
  5. Node Version:v6.9.4

当前版本与作者成书版本有所不同。
例如作者成书的时候plugin皆以new关键字新建实例来使用,而译者学习的时候使用的版本则是以service的方式直接注入到需要用到类的constructor中去使用;
例如,以下代码来自— 第七课:整合本地通知与社交分享:

  1. import { Component } from '@angular/core';
  2. import { Platform } from 'ionic-angular';
  3. import { HomePage } from '../pages/home/home';
  4. import { LocalNotifications } from 'ionic-native';
  5. @Component({
  6. template: `<ion-nav [root]="rootPage"></ion-nav>`
  7. })
  8. export class MyApp {
  9. rootPage = HomePage;
  10. constructor(platform: Platform) {
  11. platform.ready().then(() => {
  12. if(platform.is('cordova')){
  13. LocalNotifications.isScheduled(1).then( (scheduled) => {
  14. if(!scheduled){
  15. let firstNotificationTime = new Date();
  16. firstNotificationTime.setHours(firstNotificationTime.getHours()+24);
  17. LocalNotifications.schedule({
  18. id: 1,
  19. title: 'Snapaday',
  20. text: 'Have you taken your snap today?',
  21. at: firstNotificationTime,
  22. every: 'day'
  23. });
  24. }
  25. });
  26. }
  27. });
  28. }
  29. }

但是译者使用的最新版本里面应该是这样去用的:

  1. import { Component } from '@angular/core';
  2. import { Platform } from 'ionic-angular';
  3. import { HomePage } from '../pages/home/home';
  4. import { LocalNotifications } from '@ionic-native/local-notifications';
  5. @Component({
  6. template: `<ion-nav [root]="rootPage"></ion-nav>`
  7. })
  8. export class MyApp {
  9. rootPage = HomePage;
  10. constructor(platform: Platform,public localNotification:LocalNotification) {
  11. platform.ready().then(() => {
  12. if(platform.is('cordova')){
  13. this.localNotification.isScheduled(1).then( (scheduled) => {
  14. if(!scheduled){
  15. let firstNotificationTime = new Date();
  16. firstNotificationTime.setHours(firstNotificationTime.getHours()+24);
  17. this.localNotification.schedule({
  18. id: 1,
  19. title: 'Snapaday',
  20. text: 'Have you taken your snap today?',
  21. at: firstNotificationTime,
  22. every: 'day'
  23. });
  24. }
  25. });
  26. }
  27. });
  28. }
  29. }

注意LocalNotification的使用方式以及导入方式。

又如,所有的native api都已分包,具体可以参考官方文档用法。

用到的一些名词:(更新与2017/5/15)

  • default 默认
  • handler 操作器(由于昨天读文章看到一般翻译为:句柄,所以才会有这里的名词约定)
  • method:方法
  • function:函数
  • native:本地,从3.4开始翻译为【本机】,前面的翻译有空在核对
  • local:本地(会有备注和上面的进行区分)
  • functionality:功能
  • feature:特性
  • item:条目,列表项
  • provider:提供者
  • property,attribute:属性(很难区分)
  • helper:助手,助理
  • instance:实例
  • object:对象
  • build:构建
  • subscribe:订阅(针对Observable)
  • splash screen:闪屏,启动画面(有更好的翻译请告诉我)

译者当前学习完后的可用代码在此,仅限与代码部分:

source_code:ionic v3.1.1