Mathi
Mathi

Reputation: 45

Push notification from python to IOS in firebase

I am working on project to trigger notification to android and IOS using python in firebase.

Android get received but IOS did not receive any notification

##This is my code:

def sendPush(notificationTitle, notificationMessage,registration_token):
    message = messaging.MulticastMessage(
    tokens = registration_token,
    data={"channelName":"abc"},
    android=messaging.AndroidConfig(
        priority='high',
        notification=messaging.AndroidNotification(title=notificationTitle,
            body=notificationMessage,
            color='#ff0000', default_light_settings="true", priority="max",  default_sound ="true"
            ),
        ),
    )

    response = messaging.send_multicast(message) ###trigger notification

   print(response.failure_count,"failure_counts") ##to check failure count
   print('Successfully sent message:', 
   response.success_count,response.failure_count,len(registration_token))

it show message as successfully send when triggerd but device did not get any notification

Upvotes: 0

Views: 1224

Answers (1)

Mathi
Mathi

Reputation: 45

I can trigger notification for IOS by adding separate configuration for apns

message = messaging.MulticastMessage(
        tokens = registration_token,
        data={"channelName":"abc"},
        notification=messaging.Notification(
            title=notificationTitle,
            body=notificationMessage,
        ),
        android=messaging.AndroidConfig(
            priority='normal',
            notification=messaging.AndroidNotification(
               color='#ff0000', default_light_settings="true", priority="max", default_sound ="true",
            ),
        ),
        apns=messaging.APNSConfig(
            payload=messaging.APNSPayload(
                aps=messaging.Aps(badge=42),
            ),
        ),
       
    )
    response = messaging.send_multicast(message) 

referred from:https://github.com/firebase/firebase-admin-python/blob/master/snippets/messaging/cloud_messaging.py

Upvotes: 1

Related Questions