我尝试通过为iOS设置新的React Native Project来关注starter tutorial . 但登录按钮似乎不起作用 . 任何帮助表示赞赏 .
这是index.ios.js:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
const FBSDK = require('react-native-fbsdk');
const {
LoginButton
} = FBSDK;
var Login = React.createClass({
render: function() {
return (
<View>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
alert("login has finished with permissions: " + result.grantedPermissions)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
</View>
);
}
});
class AwesomeProject extends Component {
render() {
return (
<View style={styles.container}>
<Text>
Login to Facebook
</Text>
<Login />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
shareText: {
fontSize: 20,
margin: 10,
}
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
以及模拟器的屏幕截图:
1 回答
您需要在应用程序的项目中链接sdk的iOS项目 .
如果您正在使用react-native-sdk v0.2.0,则rnpm将负责此步骤,您可以按照提示here完成设置 .
如果您使用的是旧版本,则需要在YourApp.xcodeproj中链接react-native-fbsdkxxx.xcodeproj . 按照https://facebook.github.io/react-native/docs/linking-libraries-ios.html中的手动链接步骤进行操作