الدروس
إرسال الإشعارات
نسخ الصفحة
اسأل في اللحظة المناسبة، وذّكر من قال نعم، وأرسل من خادمك، وافتح الشاشة الصحيحة عندما يتم النقر على إشعار.
#1. اسأل عندما يساعد
async function waitForOpponent(room) {
if (!Lia.notificationsAllowed) {
try {
const { allowed } = await Lia.requestNotifications();
if (allowed) await api("/api/notify-me", { allowed: true });
} catch (error) {
// "notifications_off": your app can't send them; carry on without.
}
}
showWaiting(room);
}
// They can also turn them on or off from your app's ⋯ menu.
Lia.on("notificationsChanged", function (data) {
api("/api/notify-me", { allowed: data.allowed });
});Lia لم تتمكن'لإخبار خادمك عندما يسمح أحد بالإشعارات، لذلك أخبره بنفسك، كما هو مذكور أعلاه. أو اجعل الأمور أبسط: أرسل عندما يكون لديك شيء لتقوله، وتعامل not_allowed كـ "لا".
#2. أرسل من خادمك
async function notify(playerId, text, startParam) {
try {
return await lia("POST", "/notifications", { playerId, text, startParam });
} catch (error) {
const code = error.data?.error;
if (code === "not_allowed") return db.setNotify(playerId, false); // they said no or stopped
if (code === "rate_limited") return db.retryLater(playerId, error.data.retryAt); // retryAt may be missing
if (code === "bad_text") console.warn("Lia refused the text:", error.data.problem);
throw error;
}
}
await notify(opponent, "@amara played. Your move.", "room-a81c2e09f4");#3. افتح الشاشة الصحيحة
function route(startParam) {
if (startParam?.startsWith("room-")) openRoom(startParam);
}
Lia.init().then(function () { route(Lia.startParam); Lia.ready(); });
Lia.on("startParam", function (data) { route(data.startParam); });#اكتبهم
- حتى 180 رموز., سطر واحد. Lia يعرضه تحت تطبيقك'اسمها، لذلك لا'ابدأ بها.
- لا روابط، أو أرقام هواتف أو كلمات مشبوهة. يرفض Liaها بـ
bad_textوproblemمنlink,phoneأوscam. startParam هو الطريقة التي تربط بها تطبيقك. - اجعل كل واحد مهمًا. يمكن لتطبيقك إرسال شخص واحد 3 يوميًا (إلا إذا غير فريق Lia ذلك)، كل ساعة، وكل التطبيقات معًا 6 يوميًا. استخدمها في الأشياء التي يريد الشخص معرفتها.
- اكتب بلغتهم. احتفظ بكل لاعب's
Lia.languageعلى خادمك عندما يفتحون تطبيقك، ويرسلوه فيه.
#الاختبار
المختبرات تحصل على إشعارات تجريبية من مفتاح الاختبار الخاص بك كل 30 ثوانٍ ومرة واحدة على الأقل 20 في اليوم، ولا يمكنها'ت تُحسب لجموعتهم اليومية من جميع التطبيقات. انظر الاختبار.
تم الترجمة تلقائيًا. الإنجليزية هي مصدر الحقيقة. اقرأ باللغة الإنجليزية