Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Upon launching the app, a web page in mobile Safari opens firs #98

Open
bashen1 opened this issue May 16, 2018 · 5 comments
Open

Upon launching the app, a web page in mobile Safari opens firs #98

bashen1 opened this issue May 16, 2018 · 5 comments

Comments

@bashen1
Copy link

bashen1 commented May 16, 2018

We noticed an issue in your app that contributes to a lower quality user experience than Apple users expect:

 - Upon launching the app, a web page in mobile Safari opens first, then returns to the app. The user should be able to use the app immediately upon launch.

Next Steps

To resolve this issue, please revise your app to address all instances of this type of issue.

@bashen1
Copy link
Author

bashen1 commented May 17, 2018

已经用react-native-safari-view配合解决
react-native.js

import {
  Linking,
  Platform
} from 'react-native'; // eslint-disable-line import/no-unresolved, max-len
import SafariView from 'react-native-safari-view';

let previousOnLinkChange;

export const dance = (authUrl) => {
  // Use SafariView on iOS
  if (Platform.OS === 'ios') {
    if (previousOnLinkChange) {
      Linking.removeEventListener('url', previousOnLinkChange);
    }
    return SafariView.show({
      url: authUrl,
      readerMode: false,
      fromBottom: true,
      tintColor: '#000',
      barTintColor: '#fff'
    }).then(() => new Promise((resolve, reject) => {
      const handleUrl = (url) => {
        if (!url || url.indexOf('fail') > -1) {
          reject(url);
        } else {
          resolve(url);
        }
        SafariView.dismiss();
      };

      const onLinkChange = ({url}) => {
        Linking.removeEventListener('url', onLinkChange);
        previousOnLinkChange = undefined;
        handleUrl(url);
      };

      Linking.addEventListener('url', onLinkChange);

      previousOnLinkChange = onLinkChange;
    }));
  }
  // Or Linking.openURL on Android
  else {
    if (previousOnLinkChange) {
      Linking.removeEventListener('url', previousOnLinkChange);
    }
    return Linking.openURL(authUrl)
      .then(() => new Promise((resolve, reject) => {
        const handleUrl = (url) => {
          if (!url || url.indexOf('fail') > -1) {
            reject(url);
          } else {
            resolve(url);
          }
        };

        const onLinkChange = ({url}) => {
          Linking.removeEventListener('url', onLinkChange);
          previousOnLinkChange = undefined;
          handleUrl(url);
        };

        Linking.addEventListener('url', onLinkChange);

        previousOnLinkChange = onLinkChange;
      }));
  }
};

export const request = fetch;

@ayushnawani
Copy link

ayushnawani commented May 18, 2018

@bashen1 same message came for me also. did the above solution worked for you ?

@bashen1
Copy link
Author

bashen1 commented May 19, 2018

@ayushnawani Yes

@ayushnawani
Copy link

@bashen1 you should create one pull request so it can be merged. @adamjmcgrath is it possible?

@adamjmcgrath
Copy link
Owner

Sure, happy to look at a PR. Although see my comment #86 (comment) about including react-native-safari-view

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants