Walka z iphonem v2
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
Aby zapewnić bezpieczeństwo Twojego zamówienia, musimy upewnić się, że znajdujesz się na terenie
|
Aby zapewnić bezpieczeństwo Twojego zamówienia, musimy upewnić się, że znajdujesz się na terenie
|
||||||
restauracji.<br><br>Prosimy o udzielenie zgody na dostęp do lokalizacji w przeglądarce.
|
restauracji.<br><br>Prosimy o udzielenie zgody na dostęp do lokalizacji w przeglądarce.
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-primary" style="margin-top: 24px; max-width: 250px; margin-left: auto; margin-right: auto;"
|
<button id="geoActionBtn" class="btn btn-primary" style="margin-top: 24px; max-width: 250px; margin-left: auto; margin-right: auto;"
|
||||||
onclick="initGeolocation()">Udziel zgody / Sprawdź</button>
|
onclick="initGeolocation()">Udziel zgody / Sprawdź</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -979,19 +979,34 @@ function startApp() {
|
|||||||
}, 25000);
|
}, 25000);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.initGeolocation = function () {
|
function showGeoConsentScreen() {
|
||||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
|
||||||
if (isIOS) {
|
|
||||||
// Tymczasowo pomijamy weryfikację GPS tylko na urządzeniach Apple
|
|
||||||
// (wymagają bezwzględnie poprawnego certyfikatu HTTPS, inaczej blokują bez pytania)
|
|
||||||
console.warn("Bypassing geolocation on iOS.");
|
|
||||||
startApp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const geoScreen = document.getElementById("geoScreen");
|
const geoScreen = document.getElementById("geoScreen");
|
||||||
const loadingScreen = document.getElementById("loadingScreen");
|
const loadingScreen = document.getElementById("loadingScreen");
|
||||||
const geoMsg = document.getElementById("geoMsg");
|
const geoMsg = document.getElementById("geoMsg");
|
||||||
|
const geoActionBtn = document.getElementById("geoActionBtn");
|
||||||
|
|
||||||
|
loadingScreen.classList.add("hidden");
|
||||||
|
geoScreen.classList.remove("hidden");
|
||||||
|
|
||||||
|
if (geoMsg) {
|
||||||
|
geoMsg.innerHTML = `Aby zapewnić bezpieczeństwo Twojego zamówienia, musimy upewnić się, że znajdujesz się na terenie restauracji.<br><br>Prosimy o udzielenie zgody na dostęp do lokalizacji w przeglądarce.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geoActionBtn) {
|
||||||
|
geoActionBtn.disabled = false;
|
||||||
|
geoActionBtn.textContent = "Udziel zgody / Sprawdź";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isIOSDevice() {
|
||||||
|
return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.initGeolocation = function () {
|
||||||
|
const geoScreen = document.getElementById("geoScreen");
|
||||||
|
const loadingScreen = document.getElementById("loadingScreen");
|
||||||
|
const geoMsg = document.getElementById("geoMsg");
|
||||||
|
const geoActionBtn = document.getElementById("geoActionBtn");
|
||||||
|
|
||||||
const bypassHosts = ['localhost', '127.0.0.1', '192.168.20.84'];
|
const bypassHosts = ['localhost', '127.0.0.1', '192.168.20.84'];
|
||||||
if (window.location.protocol === 'http:' && bypassHosts.includes(window.location.hostname)) {
|
if (window.location.protocol === 'http:' && bypassHosts.includes(window.location.hostname)) {
|
||||||
@@ -1000,6 +1015,17 @@ window.initGeolocation = function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!window.isSecureContext) {
|
||||||
|
geoMsg.innerHTML = `<b style="color: #ff6b6b;">Ta strona nie jest uruchomiona w bezpiecznym trybie HTTPS.</b><br><br>
|
||||||
|
Przeglądarki mobilne blokują geolokalizację bez pytania, jeśli adres nie zaczyna się od <b>https://</b>.<br><br>
|
||||||
|
Otwórz aplikację przez HTTPS i spróbuj ponownie.`;
|
||||||
|
if (geoActionBtn) {
|
||||||
|
geoActionBtn.disabled = false;
|
||||||
|
geoActionBtn.textContent = "Spróbuj ponownie";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
loadingScreen.classList.add("hidden");
|
loadingScreen.classList.add("hidden");
|
||||||
geoScreen.classList.remove("hidden");
|
geoScreen.classList.remove("hidden");
|
||||||
|
|
||||||
@@ -1009,6 +1035,10 @@ window.initGeolocation = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
geoMsg.innerHTML = "Sprawdzamy Twoją lokalizację...";
|
geoMsg.innerHTML = "Sprawdzamy Twoją lokalizację...";
|
||||||
|
if (geoActionBtn) {
|
||||||
|
geoActionBtn.disabled = true;
|
||||||
|
geoActionBtn.textContent = "Sprawdzanie...";
|
||||||
|
}
|
||||||
|
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
(position) => {
|
(position) => {
|
||||||
@@ -1024,14 +1054,27 @@ window.initGeolocation = function () {
|
|||||||
startApp();
|
startApp();
|
||||||
// setTimeout(() => showToast(`Lokalizacja zweryfikowana (Dystans: ${Math.round(dist)}m, Dokładność: ${Math.round(accuracy)}m)`), 2000);
|
// setTimeout(() => showToast(`Lokalizacja zweryfikowana (Dystans: ${Math.round(dist)}m, Dokładność: ${Math.round(accuracy)}m)`), 2000);
|
||||||
} else {
|
} else {
|
||||||
|
if (geoActionBtn) {
|
||||||
|
geoActionBtn.disabled = false;
|
||||||
|
geoActionBtn.textContent = "Spróbuj ponownie";
|
||||||
|
}
|
||||||
geoMsg.innerHTML = `Wydaje się, że jesteś poza restauracją (ok. ${Math.round(dist)}m od nas).<br>Nasza aplikacja działa tylko na miejscu.<br><br>
|
geoMsg.innerHTML = `Wydaje się, że jesteś poza restauracją (ok. ${Math.round(dist)}m od nas).<br>Nasza aplikacja działa tylko na miejscu.<br><br>
|
||||||
<small style="color: #888;">Debug: Twoja odległość: ${Math.round(dist)}m, Dokładność sygnału: ${Math.round(accuracy)}m</small><br><br>
|
<small style="color: #888;">Debug: Twoja odległość: ${Math.round(dist)}m, Dokładność sygnału: ${Math.round(accuracy)}m</small><br><br>
|
||||||
Jeśli to błąd GPS lub słaby sygnał, spróbuj ponownie za chwilę.`;
|
Jeśli to błąd GPS lub słaby sygnał, spróbuj ponownie za chwilę.`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.code === error.PERMISSION_DENIED) {
|
if (geoActionBtn) {
|
||||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
geoActionBtn.disabled = false;
|
||||||
|
geoActionBtn.textContent = "Spróbuj ponownie";
|
||||||
|
}
|
||||||
|
const deniedBecauseInsecure = /secure origins|only secure|https/i.test(String(error.message || ""));
|
||||||
|
if (deniedBecauseInsecure) {
|
||||||
|
geoMsg.innerHTML = `<b style="color: #ff6b6b;">Przeglądarka zablokowała lokalizację z powodu braku HTTPS.</b><br><br>
|
||||||
|
Geolokalizacja działa tylko na bezpiecznym adresie <b>https://</b> (lub localhost).<br>
|
||||||
|
Otwórz aplikację przez HTTPS i spróbuj ponownie.`;
|
||||||
|
} else if (error.code === error.PERMISSION_DENIED) {
|
||||||
|
const isIOS = isIOSDevice();
|
||||||
|
|
||||||
let instructions = '';
|
let instructions = '';
|
||||||
if (isIOS) {
|
if (isIOS) {
|
||||||
@@ -1059,6 +1102,8 @@ window.initGeolocation = function () {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(() => {
|
if (isIOSDevice()) {
|
||||||
|
showGeoConsentScreen();
|
||||||
|
} else {
|
||||||
initGeolocation();
|
initGeolocation();
|
||||||
}, 600);
|
}
|
||||||
Reference in New Issue
Block a user