在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ HTML/ iOS 推送通知
JavaScript 環(huán)境
計時器
Native 模塊(iOS)
入門
在設備上運行
ProgressBarAndroid
iOS 應用程序狀態(tài)
網(wǎng)絡
ToolbarAndroid
測試
輔助功能
網(wǎng)絡信息
DrawerLayoutAndroid
樣式表
手勢應答系統(tǒng)
與現(xiàn)有的應用程序集成
樣式
教程
不透明觸摸
調(diào)試 React Native 應用
iOS 活動指示器
導航器
無反饋觸摸
動畫布局
Web 視圖
鏈接庫
像素比率
React Native 官網(wǎng)首頁介紹
iOS 導航器
交互管理器
全景響應器
SwitchAndroid
TabBarIOS.Item
相機滾動
ToastAndroid
iOS 震動
BackAndroid
文本輸入
iOS 選擇器
應用程序注冊表
iOS 開關(guān)
滾動視圖
iOS 日期選擇器
iOS 警告
iOS 鏈接
視圖
圖片
列表視圖
異步存儲
Native UI 組件(Android)
iOS 滑塊
Map 視圖
高亮觸摸
iOS 推送通知
文本
定位
iOS 狀態(tài)欄
Native UI 組件(iOS)
在設備上運行(Android)
Native 模塊(Android)
Flexbox
已知 Issues
iOS 選項卡
安裝 Android 運行環(huán)境

iOS 推送通知

為你的應用程序處理推送通知,包括權(quán)限的處理和圖標標記數(shù)量。

為了啟動和運行,在Apple上配置您的通知 和服務器端系統(tǒng)。為了得到一個想法,這里是 解析指南

方法

static setApplicationIconBadgeNumber(number: number)

在主屏幕上為應用程序的圖標設置標記數(shù)量

static getApplicationIconBadgeNumber(callback: Function)

在主屏幕上為應用程序的圖標獲取當前的標記數(shù)量

static addEventListener(type: string, handler: Function)

當應用程序在前臺或者后臺運行的時候,為了遠程通知鏈接一個監(jiān)聽器。

處理程序?qū)砸粋€ PushNotificationIOS 的實例的形式被調(diào)用

static requestPermissions()

從iOS上請求所有的通知權(quán)限,提示用戶對話框

static checkPermissions(callback: Function)

查看當前正被啟用的推送權(quán)限。Callback 函數(shù)將被一個 permission 的對象調(diào)用:

  • alert :boolean
  • badge :boolean
  • sound :boolean

static removeEventListener(type: string, handler: Function)

刪除事件監(jiān)聽器。為了防止內(nèi)存泄露,該操作在 componentWillUnmount 里完成。

static popInitialNotification()

如果應用程序從一個通知被冷發(fā)射,那么一個原始通知將變成可用狀態(tài)。 popInitialNotification 的第一個調(diào)用者將獲取最初的通知對象,或者為 null。后續(xù)的調(diào)用將返回 null。

constructor(nativeNotif)

你自己可能永遠都不需要 instansiate PushNotificationIOS。你只需要監(jiān)聽 notification 事件并且調(diào)用 popInitialNotification就足夠了。

getMessage()

getAlert 的一個別名,該函數(shù)是為了獲取通知的主要消息字符串

getSound()

aps 對象中獲取聲音字符串

getAlert()

aps 對象中獲取通知的主要消息字符串

getBadgeCount()

aps 對象中獲取標記數(shù)量

getData()

在通知上獲取數(shù)據(jù)對象

例子

Edit on GitHub

    'use strict';
    var React = require('react-native');
    var {
      AlertIOS,
      PushNotificationIOS,
      StyleSheet,
      Text,
      TouchableHighlight,
      View,
    } = React;
    var Button = React.createClass({
      render: function() {
        return (
          <TouchableHighlight
            underlayColor={'white'}
            style={styles.button}
            onPress={this.props.onPress}>
            <Text style={styles.buttonLabel}>
              {this.props.label}
            </Text>
          </TouchableHighlight>
        );
      }
    });
    class NotificationExample extends React.Component {
      componentWillMount() {
        PushNotificationIOS.addEventListener('notification', this._onNotification);
      }
      componentWillUnmount() {
        PushNotificationIOS.removeEventListener('notification', this._onNotification);
      }
      render() {
        return (
          <View>
            <Button
              onPress={this._sendNotification}
              label="Send fake notification"
           />
          </View>
        );
      }
      _sendNotification() {
        require('RCTDeviceEventEmitter').emit('remoteNotificationReceived', {
          aps: {
            alert: 'Sample notification',
            badge: '+1',
            sound: 'default',
            category: 'REACT_NATIVE'
          },
        });
     }
      _onNotification(notification) {
        AlertIOS.alert(
          'Notification Received',
          'Alert message: ' + notification.getMessage(),
          [{
            text: 'Dismiss',
            onPress: null,
          }]
        );
      }
    }
    class NotificationPermissionExample extends React.Component {
      constructor(props) {
        super(props);
        this.state = {permissions: null};
      }
      render() {
        return (
          <View>
            <Button
              onPress={this._showPermissions.bind(this)}
              label="Show enabled permissions"
            />
            <Text>
              {JSON.stringify(this.state.permissions)}
            </Text>
          </View>
        );
      }
      _showPermissions() {
        PushNotificationIOS.checkPermissions((permissions) => {
          this.setState({permissions});
        });
      }
    }
    var styles = StyleSheet.create({
      button: {
        padding: 10,
        alignItems: 'center',
        justifyContent: 'center',
      },
      buttonLabel: {
        color: 'blue',
      },
    });
    exports.title = 'PushNotificationIOS';
    exports.description = 'Apple PushNotification and badge value';
    exports.examples = [
    {
      title: 'Badge Number',
      render(): React.Component {
        PushNotificationIOS.requestPermissions();
        return (
         <View>
            <Button
              onPress={() => PushNotificationIOS.setApplicationIconBadgeNumber(42)}
              label="Set app's icon badge to 42"
            />
            <Button
              onPress={() => PushNotificationIOS.setApplicationIconBadgeNumber(0)}
              label="Clear app's icon badge"
            />
          </View>
        );
      },
    },
    {
      title: 'Push Notifications',
      render(): React.Component {
        return <NotificationExample />;
      }
    },
    {
      title: 'Notifications Permissions',
      render(): React.Component {
        return <NotificationPermissionExample />;
      }
    }];
上一篇:動畫布局下一篇:文本輸入