Skip to content

Example: Delayed Push

NSString *message = @"Hello!";
double seconds = 10.0;

PublishOptions *publishOptions = [PublishOptions new];
[publishOptions setHeadersWithHeaders:@{@"ios-alert": @"Alert message", @"ios-badge": @1, @"ios-sound": @"default"}];

DeliveryOptions *deliveryOptions = [DeliveryOptions new];
deliveryOptions.publishAt = [NSDate dateWithTimeIntervalSinceNow:seconds];
[deliveryOptions setPublishPolicyWithPublishPolicy:PublishPolicyEnumPUSH];

[Backendless.shared.messaging publishWithChannelName:@"default" message:message publishOptions:publishOptions deliveryOptions:deliveryOptions responseHandler:^(MessageStatus *messageStatus) {
    NSLog(@"Message status: %@", messageStatus);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let message = "Hello!"
let seconds: Double = 10.0

let publishOptions = PublishOptions()
publishOptions.setHeaders(headers: ["ios-alert": "Alert message", "ios-badge": 1, "ios-sound": "default"])

let deliveryOptions = DeliveryOptions()
deliveryOptions.publishAt = Date(timeIntervalSinceNow:seconds)
deliveryOptions.setPublishPolicy(publishPolicy: PublishPolicyEnum.PUSH.rawValue)

Backendless.shared.messaging.publish(channelName: "default", message: message, publishOptions: publishOptions, deliveryOptions: deliveryOptions, responseHandler: { messageStatus in
    print("Message status: \(messageStatus)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})