Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openURL doesn't reject promise after pressing Cancel #24830

Closed
jlocke2 opened this issue May 13, 2019 · 8 comments
Closed

openURL doesn't reject promise after pressing Cancel #24830

jlocke2 opened this issue May 13, 2019 · 8 comments
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@jlocke2
Copy link

jlocke2 commented May 13, 2019

Based on the documentation for openURL, I expect the returned promise to be rejected when pressing Cancel on the confirmation alert in iOS.

React Native version:

React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
      Memory: 428.16 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.12.0 - /usr/local/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 25, 26, 27
        Build Tools: 23.0.1, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 27.0.3, 28.0.1, 28.0.3
        System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.8 => 0.59.8
    npmGlobalPackages:
      create-react-native-app: 1.0.0
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7
      solidarity-react-native: 2.0.1

Steps To Reproduce

  1. Call openURL on a phone number.
  2. Press the Cancel option.

Describe what you expected to happen:

  1. Promise is rejected.

Describe what actually happens:

  1. Promise is resolved.

Snack, code example, or link to a repository:
https://snack.expo.io/S1g2RMvhE

Code snippet:

import React, { Component } from 'react'
import { View, StyleSheet, Button, Linking, Alert } from 'react-native'

export default class App extends Component {
  handlePress = () => {
    const link = 'tel:2125551212'
      Linking.openURL(link)
        .then(() => Alert.alert('success'))
        .catch(() => Alert.alert('cancel'))
  }

  render() {
    return (
      <View style={styles.container}>
        <Button title="Test Button" onPress={this.handlePress} />
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
})
@jlocke2 jlocke2 added the Bug label May 13, 2019
@troZee
Copy link
Contributor

troZee commented May 24, 2019

Tested on Android device. After click on button and choose application, app redirect correctly. Probably you want to use canOpenURL(), don't you ?

@jlocke2
Copy link
Author

jlocke2 commented May 24, 2019

@PTROCKI - Thanks for the response, but that isn't the issue I'm reporting.

The phone number by this point has already passed canOpenURL. In iOS, the user is given a prompt to confirm or cancel the action. Per the documentation, pressing Cancel should reject the promise instead of resolving it.

@troZee
Copy link
Contributor

troZee commented May 27, 2019

@jlocke2 do you know, if this works before ? I checked the code and I found

[RCTSharedApplication() openURL:url options:@{} completionHandler:^(BOOL success) {

Reject will be call, if url is malformed or has wrong format. Probably there is a mistake in react documentation. Ios doc says:
https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl

@christopher-18
Copy link

Any update on this? I want to detect whether the user pressed the chrome option or pressed the hardware back button , on opening some link into external browser like chrome. @pakoito @jlocke2

@pakoito
Copy link
Contributor

pakoito commented Aug 7, 2019

I do not work on React Native, I'm unsure why I was @-ed

@stale
Copy link

stale bot commented Nov 5, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 5, 2019
@stale
Copy link

stale bot commented Nov 12, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Nov 12, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Nov 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

4 participants