Programing

반응-원호 연결 AddEventListener가 작동하지 않음

c10106 2022. 4. 3. 19:44
반응형

반응-원호 연결 AddEventListener가 작동하지 않음

안녕, 나는 Linking 변경사항을 듣기 위해 React-Native의 Linking 라이브러리를 사용하려고 했는데, 나는 https://facebook.github.io/react-native/docs/linking.html의 지시를 따랐다.open을 사용하여 외부 URL을 열 수 있다.URL 그러나 Linking.addEventListener는 나에게 작동하지 않는 것 같다.코드 조각을 복사했어

componentDidMount() {
  Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
  Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
  console.log(event.url);
}

그것은 나에게 오류를 주지 않지만 _handleOpen.앱이 외부 URL을 열면 URL이 호출되지 않는다.

왜 이런 사건인지, 어떻게 고쳐야 하는지 궁금하다.

링크는 앱이 의도를 통해 시작되면 구체적인 방법이 있기 때문이다.

다음을 사용해 보십시오.

componentDidMount() {
  Linking.getInitialURL().then((ev) => {
    if (ev) {
      this._handleOpenURL(ev);
    }
  }).catch(err => {
      console.warn('An error occurred', err);
  });
  Linking.addEventListener('url', this._handleOpenURL);
}

이틀 동안 겨우 고친 것과 똑같은 문제가 있었어.여기 내 단계가 있는데, 나는 이 문제를 해결하기 위해 관리해야 할 다음 단계에도 도움이 되기를 바란다.

  1. 버전에 대한 기본 문서 대응(중요) - https://facebook.github.io/react-native/versions으로 이동하십시오.
  2. 연결 API 설명서로 이동(단계에 따라)

내 경우에는 이 방법을 추가했을 뿐이다.

// iOS 9.x or newer
#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

그 이후에는 이벤트 청취자가 제대로 활동하게 된다.8.x 및 bellow용 코드 조각이 있는 IOS 버전을 확인하십시오.

엑스포에서 탈출한 모든 사람들을 위해 - AppDelegate에 이 코드를 추가할 필요가 없다(여기 설명서에 명시된 것과 달리: https:///reactnative.dev/docs/0.60/linking).왜 이런 일이 일어나는지 모르겠고 왜 문서에 이런 내용이 없는지도 모르겠어.아마도 당신이 탈출하지 않았다고 가정하는 것일 겁니다

    - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
 return [RCTLinkingManager application:application
                  continueUserActivity:userActivity
                    restorationHandler:restorationHandler];
}

그냥 그렇게 놔둬.

    - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
  return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

제거하자마자.Linking.addEventListener('url', this._handleOpenURL);날 위해 일하기 시작했어

연결 문제에서 문제에 직면하고 있었는데, 나는 수신기 코드를 제거했고, 그리고 나서 내 코드가 작동하고 있었고, 내 코드는 그렇게 되었다.

참조URL: https://stackoverflow.com/questions/39937092/react-native-linking-addeventlistener-not-working

반응형