card: кнопка «Добавить в контакты» + надёжное открытие vCard на iOS

This commit is contained in:
Nik
2026-06-08 11:00:18 +03:00
parent 80f0367e72
commit f41450eca8
+10 -4
View File
@@ -55,15 +55,21 @@ export function CardPage() {
if (b64 && b64.length < 60000) lines.push(`PHOTO;ENCODING=b;TYPE=${type}:${b64}`); if (b64 && b64.length < 60000) lines.push(`PHOTO;ENCODING=b;TYPE=${type}:${b64}`);
} }
lines.push('END:VCARD'); lines.push('END:VCARD');
const vcard = lines.join('\r\n');
try { try {
const blob = new Blob([lines.join('\r\n')], { type: 'text/vcard;charset=utf-8' }); const isIOS = /iP(hone|ad|od)/.test(navigator.userAgent);
if (isIOS) {
window.location.href = 'data:text/vcard;charset=utf-8,' + encodeURIComponent(vcard);
} else {
const blob = new Blob([vcard], { type: 'text/vcard;charset=utf-8' });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const a = document.createElement('a'); const a = document.createElement('a');
a.href = url; a.download = `${card.slug}.vcf`; a.href = url; a.download = `${card.slug}.vcf`;
document.body.appendChild(a); a.click(); a.remove(); document.body.appendChild(a); a.click(); a.remove();
setTimeout(() => URL.revokeObjectURL(url), 1000); setTimeout(() => URL.revokeObjectURL(url), 1000);
toast('Контакт сохранён ✓'); }
} catch { toast('Откройте на телефоне для сохранения'); } toast('Открываю карточку контакта…');
} catch { toast('Не удалось открыть'); }
} }
function toast(msg: string) { function toast(msg: string) {
const t = document.getElementById('cp-toast'); const t = document.getElementById('cp-toast');
@@ -120,7 +126,7 @@ export function CardPage() {
<button className="save reveal d5" onClick={saveContact}> <button className="save reveal d5" onClick={saveContact}>
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" /><circle cx="12" cy="7" r="4" /></svg> <svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" /><circle cx="12" cy="7" r="4" /></svg>
Сохранить контакт Добавить в контакты
</button> </button>
{card.product_title && ( {card.product_title && (