react-native-orientation: Can't read getInitialOrientation of undefined
I am using react-native 0.39.2
and "react-native-orientation": "^1.17.0"
My code looks like below. I will get Can't read getInitialOrientation of undefined
error when executing this code. I have run link
on this project.
import Orientation from 'react-native-orientation';
componentWillMount(){
console.log('xxxx:', Orientation.getInitialOrientation());
}
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 5
- Comments: 16
For anyone who still is having this problem in iOS, you need to manually link the dependencies even if you ran react-native-link. To link frameworks and libraries:
Your project / the target / General -> Link Frameworks and Libraries
and copy Libraries/RCTOrientation.xcodeproj/Products/libRCTOrientaton.a into the link framework and libraries,
also you need to add this file your appdelagate.m file
The Build Phase/Link Binary and Libraries was already linked if you ran react-native-link If not put the libRCTOrientaton.a file into the build phases as well and make sure its set to required.
Once this was done the problem was fixed for me. Hope this helps.
I rebuild the whole thing but still got
undefined
error. I printed theOrientation
and got below output:but when I call
Orientation.getInitialOrientation()
, I got below error:This error was thrown from
getInitialOrientation()
method.No libRCTOrientation. A file? I don’t have the link.
After running link you will need to rebuild the application, hot/live reloading will not pull in the newly linked native code.