question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linking.getInitialURL in standalone in iOS fails to pass additional data in the URL

See original GitHub issue

When using Linking.getInitialURL to retrieve the URL (in a standalone iOS app with a custom scheme) when the app is first loaded (not when foregrounded), only the prefix is returned.

For example, attempting to open the app using custom scheme test with test://something, the URL retrieved with Linking.getInitialURL will return only the prefix test://.

Environment

Environment: OS: macOS High Sierra 10.13.4 Node: 8.9.0 Yarn: 0.22.0 npm: 5.8.0 Watchman: 4.9.0 Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.1 AI-173.4670197

Packages: (wanted => installed) expo: ^26.0.0 => 26.0.0 react: 16.3.0-alpha.1 => 16.3.0-alpha.1 react-native: https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz => 0.54.2

Diagnostics report: https://exp-xde-diagnostics.s3.amazonaws.com/gradealabs-903bc80d-7584-4adb-b9cc-a451803284e8.tar.gz

Steps to Reproduce

In order to make this as easy as possible, I’ve written a bash script to create a test project, build it for simulator, download it, and install it in the iOS simulator automatically.

  1. Create this script and run it in a scratch folder of your choosing. A test project will be created within:
#!/bin/bash

set -e

exp init test --template blank
cd test

cat > App.js <<- EOM
import React from 'react';
import { StyleSheet, Text, View, Linking } from 'react-native';

export default class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = { url: '' }
  }
  componentDidMount() {
    Linking.getInitialURL().then(url => this.setState({ url }))
  }
  render() {
    return (
      <View style={styles.container}>
        <Text>URL: {this.state.url}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
EOM

cat > app.json <<- EOM
{
  "expo": {
    "name": "test",
    "description": "This project is really great.",
    "slug": "test",
    "scheme": "test",
    "privacy": "public",
    "sdkVersion": "26.0.0",
    "platforms": ["ios", "android"],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.test.test"
    }
  }
}
EOM

rm -f /tmp/ios-app.tar.gz
exp build:ios --type simulator | grep -Eo "Successfully built standalone app: (.+)" | cut -d: -f2,3 | xargs curl -o /tmp/ios-app.tar.gz
rm -rf /tmp/test.app
tar -xvzf /tmp/ios-app.tar.gz -C /tmp

open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
while : ; do
  count=$(xcrun simctl list | grep Booted | wc -l | sed -e 's/ //g')
  [ $count -lt 1 ] || break
  sleep 1
done

xcrun simctl install booted /tmp/test.app
  1. Make sure the app is not currently running in the simulator, as we are not concerned with the behavior when the app is foregrounded

  2. Launch the app in the simulator via Safari, such as test://thisshouldwork

  3. Look for the URL being displayed in the app

Expected Behavior

The app should display: URL: test://thisshouldwork

Actual Behavior

The app displays: URL: test://

getinitialurl

Reproducible Demo

See above installation script and demo video.

EDIT: changed wget to curl in the script

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yirui94commented, Jul 3, 2018

Anyone still encountering this issue but when opening an App from a notification deep link?

1reaction
matb33commented, May 2, 2018

Confirming that this is indeed resolved with SDK 27. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linking - Expo Documentation
Helper method for constructing a deep link into your app, given an optional path and set of query parameters. Creates a URI scheme...
Read more >
Linking.getInitialURL() is not being cleared after used for ...
Linking.getInitialURL() gives us the same Url when we come back to the same page again, to Overcome this we can do a simple...
Read more >
React Native SDK - Kinde
Add the Kinde React Native SDK as a dependency. ... For iOS: You'll need to link RCTLinking to your project by following the...
Read more >
#2 Deep Linking With React Navigation | Expo ... - YouTube
Learn how to take a user to a specific screen from a deep link using react-navigation and the expo- linking module.We'll first test...
Read more >
Deep linking - React Navigation
If the app was already open, we need to update the state to reflect the incoming link. React Native provides a Linking to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found