简体   繁体   中英

How to configure Info.plist file in ejected react-native app uses expo sdk

i created an app using react-native ini projectName and i added a native module package called react-native-facebook-account-kit And i need to change Info.plist in ios folder and add app id and client token info. Also i created a pod file as facebook docs said. It works fine. Then i tried to make exactly same thing in expo. So i used this cli to create a new project create-react-native-app projectName then i run npm run eject and selected second option which is uses both react-native and expo sdk. So it created ios and android folders successfully.

BUT in ios folder there is no Info.plist file. After my search i found this doc. https://docs.expo.io/versions/latest/workflow/configuration#ios And i added some key and values into app.json like doc said.

    {
  "expo": {
    "sdkVersion": "27.0.0",
    "ios": {
      "bundleIdentifier": "com.cecil.foxtail",
      "infoPlist": {
        "FacebookAppID": "myAppId",
        "AccountKitClientToken": "myClientToken",
        "CFBundleURLTypes": [
          // ??? CONFUSED
        ]
      }
    },
    "android": {
      "package": "com.cecil.foxtail"
    }
  }
}

Here is the original Info.plist from the app which is working great.

<key>FacebookAppID</key>
  <string>{app-id}</string>
  <key>AccountKitClientToken</key>
  <string>{client-token}</string>
  <key>CFBundleURLTypes</key>
  <array>
    <dict>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>ak{client-token}</string>
      </array>
    </dict>
  </array>

So how to define these array into app.json ?

You don't need to set a custom URL Schema because expo by default sets it to your bundleIdentifier

"bundleIdentifier": "com.cecil.foxtail",

So you can call your app from another by calling something like this:-

let websiteUrl ="https://apps.apple.com/myappInstallationPage";
let SchemaUrl = 'com.cecil.foxtail://';
Linking.canOpenURL(SchemaUrl).then(supported => {
    if (supported) {
        console.log('accepted');
        return Linking.openURL(SchemaUrl);
    } else {
        console.log('an error occurred');
    }
}).catch(err => {
    Linking.openURL(websiteUrl).catch(reason => console.log('Failed to open app website!'))
    console.log('an error occurred')
});

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM