99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

iOS 推送通知

2019-08-14 14:24 更新

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

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

方法

static setApplicationIconBadgeNumber(number: number)

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

static getApplicationIconBadgeNumber(callback: Function)

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

static addEventListener(type: string, handler: Function)

當應(yīng)用程序在前臺或者后臺運行的時候,為了遠程通知鏈接一個監(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()

如果應(yīng)用程序從一個通知被冷發(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 />;
      }
    }];


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號