tony-yun
tony-yun
@tosspayments/widget-sdk-react-native/src/utils/convertUrl 문의드립니다.
"react-native": "0.73.5", "@tosspayments/widget-sdk-react-native": "^1.2.7", ConvertUrl 함수 관련 문의 드립니다. (react native 의 iOS 플랫폼 코드) 예를 들어 페이북으로 결제 시도 시 웹뷰에서 앱으로 ispmobile 스킴이 넘어오는데,(url: ispmobile://vp?TID=NICETOKN......) 귀사 라이브러리의 launchApp 함수는 아래와 같이 구현이 되어있습니다.
else if (Platform.OS === 'ios') {
try {
const appLink = await this.getAppLink();
if (appLink) {
return Linking.openURL(appLink);
} else {
const marketUrl = await this.getMarketUrl();
return Linking.openURL(marketUrl);
}
else if (Platform.OS === 'ios') {
try {
const appLink = await this.getAppLink();
if (appLink) {
return Linking.openURL(appLink);
} else {
const marketUrl = await this.getMarketUrl();
return Linking.openURL(marketUrl);
}
appLink 가 기존의 스킴 주소 즉: ispmobile://... 로 설정되어 Linking.openURL 을 시도합니다. 만약 해당 페이북앱이 설치가 되어 있지 않을 경우, 열리지 않습니다. 즉 getAppLink 에서 ,
} else if (Platform.OS === 'ios') {
this.appLink =
this.appScheme === 'itmss' ? `https://${splitUrl[1]}` : this.url;
}
}

async getAppLink(): Promise<string | undefined> {
console.log('this.appLink:',this.appLink)
return this.appLink;
}
} else if (Platform.OS === 'ios') {
this.appLink =
this.appScheme === 'itmss' ? `https://${splitUrl[1]}` : this.url;
}
}

async getAppLink(): Promise<string | undefined> {
console.log('this.appLink:',this.appLink)
return this.appLink;
}
this.appLink = this.url 이며, Linking.openURL(ispmobile://...) 를 시도하기 때문에, 앱에서는 마켓으로 이동을 못합니다. 호출하는 부분은 아래와 같이 '웹뷰 연동하기' 페이지의 제시된 코드를 그대로 사용하고 있습니다.
const convertUrl = new ConvertUrl(url)

if (convertUrl.isAppLink()) {
convertUrl.launchApp().then((isLaunch) => {
if (isLaunch === false) {
}
})
} else {
return true
}
const convertUrl = new ConvertUrl(url)

if (convertUrl.isAppLink()) {
convertUrl.launchApp().then((isLaunch) => {
if (isLaunch === false) {
}
})
} else {
return true
}
사용자가 페이북앱을 설치 하지 않았을 때 마켓 페이지로 이동하게 하는 것이 목표입니다. Linking.openURL 로 열리지 않을때 catch 문으로 안넘어가고 그 자리에서 Promise Rejection 을 반환합니다. Possible Unhandled Promise Rejection (id: 16): Error: Unable to open URL: ispmobile://vp?TID=NICETOKN......
21 replies