RajeshKumar R
RajeshKumar R

Reputation: 15748

How to send push notification programmatically with Quickblox in Swift 4.0?

I got this code from their sample project.

    NSString *message = @"Hello man!";
    NSMutableDictionary *payload = [NSMutableDictionary dictionary];
    NSMutableDictionary *aps = [NSMutableDictionary dictionary];
    [aps setObject:@"default" forKey:QBMPushMessageSoundKey];
    [aps setObject:message forKey:QBMPushMessageAlertKey];
    [payload setObject:aps forKey:QBMPushMessageApsKey];
    QBMPushMessage *pushMessage = [[QBMPushMessage alloc] initWithPayload:payload];
    [QBRequest sendPush:pushMessage toUsers:@"292,300,1395" successBlock:^(QBResponse *response, QBMEvent *event) {
        // Successful response with event
    } errorBlock:^(QBError *error) {
        // Handle error
    }];

I converted this to

    let mesage = "Hello man!"
    var payload = [String:String]()
    var aps = [String:String]()
    aps[QBMPushMessageSoundKey] = "default"
    aps[QBMPushMessageAlertKey] = mesage
    payload[QBMPushMessageApsKey] = aps //Cannot assign value of type '[String : String]' to type 'String?'
    let message = QBMPushMessage(payload: payload)

Upvotes: 0

Views: 611

Answers (1)

let pushMessage = QBMPushMessage()
pushMessage.payloadDict = ["aps":aps]

Work for me :)

Upvotes: 1

Related Questions