Skip to content

Commit 57d1294

Browse files
committed
๐Ÿงช test(#180): ์นด์นด์˜ค ์ธ์•ฑ ๊ตฌ๋ถ„ ํ…Œ์ŠคํŠธ
1 parent e57022d commit 57d1294

1 file changed

Lines changed: 56 additions & 46 deletions

File tree

โ€Žsrc/app/test/page.tsxโ€Ž

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,83 +22,91 @@ interface BeforeInstallPromptEvent extends Event {
2222
}
2323

2424
const page = () => {
25-
const [deferredPrompt, setDeferredPrompt] = useState(null);
26-
const [isIOS, setIsIOS] = useState(false);
27-
const [isAndroid, setIsAndroid] = useState(false);
28-
25+
const [deferredPrompt, setDeferredPrompt] =
26+
useState<BeforeInstallPromptEvent | null>(null);
27+
const [platform, setPlatform] = useState<'ios' | 'android' | 'other'>(
28+
'other'
29+
);
30+
const [isKakaoInApp, setIsKakaoInApp] = useState(false);
2931
const [showModal, setShowModal] = useState(false);
3032

3133
useEffect(() => {
3234
const userAgent = window.navigator.userAgent.toLowerCase();
33-
const isIOSDevice = /iphone|ipad|ipod/.test(userAgent);
34-
const isAndroidDevice = /android/.test(userAgent);
35+
const isIOS = /iphone|ipad|ipod/.test(userAgent);
36+
const isAndroid = /android/.test(userAgent);
37+
const isKakao = /kakaotalk/i.test(userAgent);
3538

36-
setIsIOS(isIOSDevice);
37-
setIsAndroid(isAndroidDevice);
39+
setPlatform(isIOS ? 'ios' : isAndroid ? 'android' : 'other');
40+
setIsKakaoInApp(isKakao);
3841

39-
// Android์—์„œ๋งŒ beforeinstallprompt ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
40-
if (isAndroidDevice) {
41-
const handler = (e: any) => {
42-
console.log('๐Ÿ”ฅ beforeinstallprompt ๋ฐœ์ƒ');
43-
e.preventDefault();
44-
setDeferredPrompt(e);
45-
};
42+
if (isKakao) {
43+
if (isAndroid) {
44+
const currentUrl = window.location.href;
45+
const intentUrl = `intent://${currentUrl.replace(
46+
/^https?:\/\//,
47+
''
48+
)}#Intent;scheme=https;package=com.android.chrome;end`;
49+
window.location.href = intentUrl;
50+
} else if (isIOS) {
51+
alert(
52+
'ํ™”๋ฉด ์šฐ์ธก ํ•˜๋‹จ ๊ณต์œ ํ•˜๊ธฐ ๋ฉ”๋‰ด์—์„œ "Safari๋กœ ์—ด๊ธฐ"๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”.'
53+
);
54+
}
55+
} else {
56+
if (isAndroid) {
57+
const handler = (e: any) => {
58+
e.preventDefault();
59+
setDeferredPrompt(e);
60+
};
61+
window.addEventListener('beforeinstallprompt', handler);
62+
return () => window.removeEventListener('beforeinstallprompt', handler);
63+
}
4664

47-
window.addEventListener('beforeinstallprompt', handler);
48-
return () => {
49-
window.removeEventListener('beforeinstallprompt', handler);
50-
};
65+
// ์™ธ๋ถ€ ๋ธŒ๋ผ์šฐ์ €์ผ ๊ฒฝ์šฐ ์ง„์ž… ์‹œ ์„ค์น˜ ๋ชจ๋‹ฌ ์ž๋™ ์˜คํ”ˆ
66+
setShowModal(true);
5167
}
5268
}, []);
5369

54-
const handleInstallClick = async () => {
55-
if (isAndroid && deferredPrompt) {
70+
const handleInstall = async () => {
71+
if (platform === 'android' && deferredPrompt) {
5672
deferredPrompt.prompt();
5773
const { outcome } = await deferredPrompt.userChoice;
58-
console.log('Android ์‚ฌ์šฉ์ž ์„ ํƒ:', outcome);
74+
console.log('์„ค์น˜ ๊ฒฐ๊ณผ:', outcome);
75+
if (outcome === 'accepted') {
76+
alert('์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!');
77+
} else {
78+
alert('์„ค์น˜๊ฐ€ ์ทจ์†Œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
79+
}
5980
setDeferredPrompt(null);
6081
setShowModal(false);
61-
} else if (isIOS) {
62-
// iOS๋Š” ์•ˆ๋‚ด๋งŒ
63-
alert(
64-
'iPhone ์‚ฌ์šฉ์ž๋Š” Safari์—์„œ ๊ณต์œ  ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ [ํ™ˆ ํ™”๋ฉด์— ์ถ”๊ฐ€]๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”!'
65-
);
82+
} else if (platform === 'ios') {
83+
alert('ํ•˜๋‹จ ๊ณต์œ  ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ณ  "ํ™ˆ ํ™”๋ฉด์— ์ถ”๊ฐ€"๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”.');
6684
setShowModal(false);
6785
} else {
68-
alert('์„ค์น˜ ๊ธฐ๋Šฅ์ด ํ˜„์žฌ ํ™˜๊ฒฝ์—์„œ ์ง€์›๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');
86+
alert('ํ˜„์žฌ ํ™˜๊ฒฝ์—์„œ๋Š” ์„ค์น˜๊ฐ€ ์ง€์›๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');
6987
setShowModal(false);
7088
}
7189
};
7290

73-
const handleShowModal = () => {
74-
if (isAndroid && deferredPrompt) {
75-
setShowModal(true);
76-
} else if (isIOS) {
77-
setShowModal(true);
78-
} else {
79-
alert('๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์•„์ง ์„ค์น˜๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.');
80-
}
81-
};
82-
8391
return (
8492
<Container>
8593
<Title>PWA ์„ค์น˜ ์œ ๋„ TEST</Title>
8694
<Button
8795
buttonType="primary"
8896
text="์•ฑ ์„ค์น˜ํ•˜๊ธฐ"
89-
onClick={handleShowModal}
97+
onClick={() => setShowModal(true)}
9098
/>
9199
{showModal && (
92100
<ConfirmModal
93-
title="PWA ์„ค์น˜ํ•˜๊ธฐ"
101+
title="์•ฑ ์„ค์น˜ํ•˜๊ธฐ"
94102
sub={
95-
isIOS
96-
? 'Safari ๊ณต์œ  ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ [ํ™ˆ ํ™”๋ฉด์— ์ถ”๊ฐ€]๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”.'
97-
: 'ํ™ˆ ํ™”๋ฉด์— ์ถ”๊ฐ€ํ•˜์‹œ๊ฒ ์–ด์š”?'
103+
platform === 'ios'
104+
? 'ํ™ˆ ํ™”๋ฉด์— ์ถ”๊ฐ€ํ•˜์‹œ๊ฒ ์–ด์š”?'
105+
: '์•ฑ์„ ์„ค์น˜ํ•˜์‹œ๊ฒ ์–ด์š”?'
98106
}
99-
confirmText={isIOS ? '์•Œ๊ฒ ์Šต๋‹ˆ๋‹ค' : '์„ค์น˜ํ•˜๊ธฐ'}
107+
confirmText="์„ค์น˜ํ•˜๊ธฐ"
100108
cancelText="์ทจ์†Œ"
101-
onConfirm={handleInstallClick}
109+
onConfirm={handleInstall}
102110
onCancel={() => setShowModal(false)}
103111
/>
104112
)}
@@ -114,7 +122,8 @@ const Container = styled.div`
114122
padding: 100px 30px;
115123
height: 100vh;
116124
flex-direction: column;
117-
justify-content: space-between;
125+
justify-content: center;
126+
gap: 20px;
118127
background-image: url('/assets/login/login_bg.png');
119128
background-size: cover;
120129
background-position: center;
@@ -126,5 +135,6 @@ const Container = styled.div`
126135

127136
const Title = styled.h1`
128137
color: ${theme.colors.white};
138+
${theme.fonts.title01}
129139
text-align: center;
130140
`;

0 commit comments

Comments
ย (0)