我从他们的示例项目中获得了这段代码。

    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
    }];


我将其转换为

    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)

最佳答案

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


为我工作:)

关于ios - 如何在Swift 4.0中使用Quickblox以编程方式发送推送通知?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47109892/

10-09 02:18