簡體   English   中英

使用quickblox和IOS SDK實施預定的推送通知

[英]Implementing scheduled push notifications with quickblox and IOS sdk

在我的應用中,我想發送“計划的”推送通知。 我正在使用quickblox作為推送通知服務。 推送通知必須從應用程序本身創建,然后由quickblox在設置的日期/時間發送。 消息的目的是發送一個內容可用標志,以便該應用可以在后台獲取數據。

搜索文檔,我認為可以通過“ ApplePushEvent”實現。 但是,我無法找到任何進一步的信息。 我試圖在sendButtonDidPress部分中添加以下代碼,以向自己發送延遲5分鍾的推送通知:

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

但是什么也沒有發生,並且我在NSLog中收到“ UTF-8中無效的字節序列”錯誤。

以下是從日志中摘錄的內容:

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>

非常感謝你的幫助!

親切的問候,

Louwrens

您應該再添加一個參數並更改APEvent.type:

APEvent.pushType = QBMPushTypeAPNS;
APEvent.type = QBMEventTypeFixedDate;

試試這個,希望有幫助

有關計划推送的更多信息,請參見http://quickblox.com/developers/Messages#Create_event

我得到了與Quickblox一起使用的內容可用標志

我使用了Louwren(user3580713)問題中的以下代碼:

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

並在setObject:message之后添加了以下行

[aps setObject:@"1" forKey:@"content-available"];

現在,當iPhone處於睡眠狀態時,didReceiveRemoteNotification:fetchCompletionHandler會被調用。 我正在尋找一種添加內容可用標簽的方法,這個問題幫助我弄清楚了。 謝謝。 希望這對某人有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM