2016-07-15 4 views
0

したがって、ユーザーが着信プッシュ通知をタップすると、特定のナビゲータ・シーンにユーザーをドロップしたいとします。使用された「シーン」と「id」はJSONとして通知ペイロードに渡されます。React Native:Push Notificationをタップして関数を呼び出しますか?

しかし、私は

PushNotificationIOS.addEventListener('notification', this._onNotification.bind(this)); 

「通知」イベント内でこれらの値をどうするか見当がつかない。

明らかに、通知をタップするとアプリが表示されますが、一度機能を起動するにはどうすればいいですか?

ありがとうございます!あなたの一番上のコンポーネントで

答えて

1

、あなたの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); 
+0

perfect- thanks! –

関連する問題