How to properly use iOS only components in React Native without error in Android -


i'm new react native , testing out pushnotificationios. checkpermission call giving me error on android.

exceptionsmanager.js:61 cannot read property 'checkpermissions' of undefined 

i'm guessing because need use component on ios. how add check of os make call on ios?

here's code:

  componentwillmount: function() {     //--  need os check here??     pushnotificationios.checkpermissions((data)=> {       console.log("in comp mount: checking permission")       console.log(data.alert)       console.log(data.badge) 

what suggest splitting platform specific code in separate files.

react native detect when file has .ios. or .android. extension , load relevant platform file when required other components.

myfile.ios.js myfile.android.js 

you can require component follows:

const myfile= require('./myfile'); 

and use this

componentwillmount: function() {     //--  call logic of ever platform detected automatically     myfile.callwhatever(); 

and run platform specific code.

another way

platform module

react native provides module detects platform in app running. can use detection logic implement platform-specific code. use option when small parts of component platform-specific.

if(platform.os === 'ios') 

there platform.select can accept value

const component = platform.select({   ios: () => //function goes here,   android: () => require('componentandroid'), })(); 

link https://facebook.github.io/react-native/docs/platform-specific-code.html


Comments