在你最上面的組成部分,一個在你index.ios.js註冊,在componentDidMount
方法,你可以從通知中添加監聽器和get the data:
export default class App extends Component {
componentDidMount() {
PushNotificationIOS.addEventListener('notification', this._onNotification.bind(this));
if (notification) {
const data = notification.getData();
if (data) {
// do your thing
}
}
}
}
另一種解決方案是傳遞一個url,並執行下面的代碼,同樣在你最上面的組件的ComponentDidMount方法中:
Linking.getInitialURL().then(url => {
if (!url) {
return null;
}
// do something to decide which component to load
navigator.push({
component: YourComponent,
passProps: {
// your props
},
});
return null;
}).catch(() => null);
perfect- thanks! –