Reputation: 1
In my app, I would like to send a 'scheduled' push notification. I am using quickblox as push notification service. The push notification must be created from the app itself to be sent by quickblox at the set date/time. The purpose of the message will be to sent a content available flag, so the app can fetch data in the background.
Searching the documentation, I think this can be achieved with 'ApplePushEvent'. However I cannot find any further information on this. I tried to add the following code in the sendButtonDidPress section, to send myself a push notification delayed 5 minutes:
NSUInteger userID = ((QBUUser *)[_users objectAtIndex:[usersPickerView selectedRowInComponent:0]]).ID;
NSDate *date = [[NSDate alloc]init];
NSDate *fiveMinFromNow = [date dateByAddingTimeInterval:300];
QBMApplePushEvent *APEvent = [QBMApplePushEvent pushEvent];
APEvent.active = NO;
APEvent.name = @"test";
APEvent.type = QBMEventTypeOneShot;
APEvent.date = fiveMinFromNow;
APEvent.isDevelopmentEnvironment = YES;
APEvent.usersIDs = [NSString stringWithFormat:@"%d", userID];
NSString *message = @"Testing APNS!";
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];
APEvent.pushMessage = Pushmessage;
[QBMessages createEvent:APEvent delegate:self];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[messageBody resignFirstResponder];
However nothing happens and I receive a 'invalid byte sequence in UTF-8' error in NSLog.
Below is an extraction from the Log:
2014-04-28 11:32:52.508 Messages[1763:4603] +[QBMEvent messageToString:] -> message: {
payload = "{\"aps\":{\"sound\":\"default\",\"alert\":\"TestingAPNS\"}}";
}
2014-04-28 11:32:52.510 Messages[1763:4603] Performing async request:
POST https://api.quickblox.com/events.xml
headers:{
"QB-SDK" = "iOS 1.8.4";
"Qb-Token" = 33360a8735e91da82e588ffdbd5cd462b52420cf;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"event[date]" = 1398677872;
"event[environment]" = development;
"event[event_type]" = "one_shot";
"event[message]" = "payload=eyJhcHMiOnsic291bmQiOiJkZWZhdWx0IiwiYWxlcnQiOiJUZXN0aW5nQVBOUyJ9fQ==";
"event[name]" = test;
"event[notification_type]" = push;
"event[user][ids]" = 1026331;
}
2014-04-28 11:32:52.700 Messages[1763:1903] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Type" = "application/xml; charset=utf-8";
Date = "Mon, 28 Apr 2014 09:32:53 GMT";
"QB-Token-ExpirationDate" = "2014-04-28 11:32:43 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "422 Unprocessable Entity";
"Transfer-Encoding" = Identity;
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = b65b8c46d1bd4c316e0758f047f1f1b1;
"X-Runtime" = "0.076002";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
error:
<?xml version="1.0" encoding="UTF-8"?>
<errors type="array">
<error>
<code nil="true"/>
<message>invalid byte sequence in UTF-8</message>
</error>
</errors>
Thanks a lot for your help!
Kind regards,
Louwrens
Upvotes: 0
Views: 1328
Reputation: 13
I got the content-available flag working with Quickblox
I used the following code from Louwren's (user3580713) question:
NSString *message = @"Testing APNS!";
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];
and added the following line after setObject:message
[aps setObject:@"1" forKey:@"content-available"];
didReceiveRemoteNotification:fetchCompletionHandler now gets called when the iPhone is asleep. I was searching for a way to add the content-available tag and this question helped me figure it out. Thanks. Hope this helps somebody.
Upvotes: 0
Reputation: 18346
You should add one more parameter and change APEvent.type:
APEvent.pushType = QBMPushTypeAPNS;
APEvent.type = QBMEventTypeFixedDate;
try this, hope this help
More info about schedule pushes read here http://quickblox.com/developers/Messages#Create_event
Upvotes: 1