Firebase Cloud Messaging के Firebase Cloud Messaging HTTP v1 एपीआई की मदद से, iOS डिवाइसों पर लाइव गतिविधि की सूचनाएं दूर से भेजी, अपडेट की, और खत्म की जा सकती हैं. ध्यान दें कि लाइव गतिविधि की सुविधा का इस्तेमाल करने के लिए, आपके पास iOS 16.1 होना चाहिए. वहीं, लाइव गतिविधि की सूचना को दूर से शुरू करने के लिए, आपके पास iOS 17.2 होना चाहिए.
शुरू करने से पहले
Firebase Cloud Messaging पर लाइव गतिविधि की सुविधा का इस्तेमाल करने से पहले, Apple प्लैटफ़ॉर्म पर Firebase Cloud Messaging क्लाइंट ऐप्लिकेशन सेट अप करें में दिए गए निर्देशों का पालन करें. इससे, क्लाइंट ऐप्लिकेशन बनाया जा सकेगा और उसमें Firebase Cloud Messaging जोड़ा जा सकेगा.
लाइव गतिविधि शुरू करना
Firebase Cloud Messaging का इस्तेमाल करके, लाइव गतिविधि को दूर से शुरू करने के लिए, आपको Apple से पुश-टू-स्टार्ट टोकन लेना होगा. आपको टारगेट ऐप्लिकेशन के लिए, FCM रजिस्ट्रेशन टोकन की भी ज़रूरत होगी.
लाइव गतिविधि शुरू करने वाला पेलोड बनाने के लिए,
यहां दिए गए कोड के नमूने में
apns.payload फ़ील्ड भरें ताकि FCM
FCM का इस्तेमाल करके लाइव
गतिविधि को दूर से शुरू किया जा सके.
REST
{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TO_START_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "start", "content-state": { "demo": 1 }, "attributes-type": "DemoAttributes", "attributes": { "demoAttribute": 1 }, "alert": { "title": "test title", "body": "test body" } } } } } }
cURL
curl -X POST -H "Authorization: Bearer OAUTH2_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TO_START_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "start", "content-state": { "demo": 1 }, "attributes-type": "DemoAttributes", "attributes": { "demoAttribute": 1 }, "alert": { "title": "test title", "body": "test body" } } } } } }' https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
नमूने को API Explorer में आज़माने के लिए, चलाएं पर क्लिक करें.
लाइव गतिविधि अपडेट करना
Firebase Cloud Messaging का इस्तेमाल करके, लाइव गतिविधि को दूर से अपडेट करने के लिए, आपको Apple से पुश टोकन लेना होगा. आपको टारगेट ऐप्लिकेशन के लिए, FCM रजिस्ट्रेशन टोकन की भी ज़रूरत होगी.
लाइव गतिविधि को अपडेट करने वाला पेलोड बनाने के लिए,
यहां दिए गए कोड के नमूने में
apns.payload फ़ील्ड भरें, ताकि FCM का इस्तेमाल करके लाइव गतिविधि को दूर से अपडेट किया जा सके.
FCM
REST
{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "update", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }
cURL
curl -X POST -H "Authorization: Bearer OAUTH2_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "update", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }' https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
नमूने को API Explorer में आज़माने के लिए, चलाएं पर क्लिक करें.
लाइव गतिविधि खत्म करना
Firebase Cloud Messaging का इस्तेमाल करके, लाइव गतिविधि को खत्म करने के लिए, आपको Apple से पुश टोकन लेना होगा. आपको टारगेट ऐप्लिकेशन के लिए, FCM रजिस्ट्रेशन टोकन की भी ज़रूरत होगी.
लाइव गतिविधि को खत्म करने वाला पेलोड बनाने के लिए,
लाइव गतिविधि को दूर से खत्म करने के लिए, यहां दिए गए कोड के नमूने में
apns.payload फ़ील्ड भरें.FCM
REST
{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "dismissal-date": DISMISSAL_DATE, "event": "end", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }
cURL
curl -X POST -H "Authorization: Bearer OAUTH2_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "dismissal-date": DISMISSAL_DATE, "event": "end", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }' https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
नमूने को API Explorer में आज़माने के लिए, चलाएं पर क्लिक करें.