I am struggling creating an order with Orders v2 PayPal API.
I have the token, and I do a request with these headers to create the order:
{
"intent": "CAPTURE",
"purchase_units": [{
"description": "Payment",
"amount": {
"value": 'X',
"currency_code": "EUR",
"breakdown": {
"item_total": {
"currency_code": "EUR",
"value": 'X'
},
}
},
"items": [{
"unit_amount": {
"currency_code": "EUR",
"value": 'X'
},
"quantity": "1",
"name": 'item name',
}]
}],
"application_context": {
"brand_name": "My brand name",
"locale": "it-IT",
"return_url": 'my-return-url',
}
}
The order is created and I get the approveurl to let the user to pay.
With the approveurl I do this call:
try {
var response = await http.post(approveurl, body: jsonEncode({"payer_id": payerId}), headers: {
"content-type": "application/json",
'Authorization': 'Bearer ' + accessToken
});
final body = jsonDecode(response.body);
if (response.statusCode == 200) {
return body;
}
return null;
} catch (e) {
rethrow;
}
But I get this reponse:
url = "https://www.sandbox.paypal.com/checkoutnow?token=..."
payerId = "..."
accessToken = "..."
response = {Response}
request = {Request} POST https://www.sandbox.paypal.com/checkoutnow?token=...
statusCode = 302
reasonPhrase = "Found"
contentLength = 61
headers = {_InternalLinkedHashMap} size = 9
0 = {map entry} "paypal-debug-id" -> "95934918777a1"
1 = {map entry} "cache-control" -> "max-age=0, no-cache, no-store, must-revalidate"
2 = {map entry} "location" -> "/webapps/hermes?token=..."
3 = {map entry} "set-cookie" -> "X-PP-SILOVER=name%3DSANDBOX3.WEB.1%26silo_version%3D880%26app%3Dhermesnodeweb%26TIME%3D1595167415%26..."
4 = {map entry} "date" -> "Sun, 19 Jul 2020 14:03:35 GMT"
5 = {map entry} "vary" -> "Accept"
6 = {map entry} "strict-transport-security" -> "max-age=63072000"
7 = {map entry} "content-length" -> "61"
8 = {map entry} "content-type" -> "text/plain; charset=utf-8"
isRedirect = false
persistentConnection = true
And the response.body is:
Found. Redirecting to /webapps/hermes?token=...
With the approvalurl I do this call:
The approval URL is not for you to call. It's a web URL, not an API URL. It's for the paying customer to log in and give their approval of the payment.
However, redirecting them to it would be a bad web experience. For modern web design, you should instead offer an "in context" approval, where your site remains loaded in the background. Here's how to do that: https://developer.paypal.com/demo/checkout/#/pattern/server
With this integration you don't read the approval_url yourself, simply return the Order id when fetched from createOrder.
I am trying to download file from private window using wkwebview unfortunately unable to download the file. this is the response which i am getting.
-[DownloadHandler saveDirectoryPathForResponse:][L:124]response <NSHTTPURLResponse: 0x600000434c20> { URL: https://osxDev.slack.com/?redir=%2Ffiles-pri%2FT0B5PPLCX-FF7NT0NNA%2Fdownload%2Fchalte_chalte_-_pagalworld.org } { Status Code: 200, Headers {
"Cache-Control" = (
"private, no-cache, no-store, must-revalidate"
);
"Content-Encoding" = (
gzip
);
"Content-Length" = (
19772
);
"Content-Type" = (
"text/html; charset=utf-8"
);
Date = (
"Wed, 23 Jan 2019 11:08:19 GMT"
);
Expires = (
"Mon, 26 Jul 1997 05:00:00 GMT"
);
Pragma = (
"no-cache"
);
Server = (
Apache
);
"Set-Cookie" = (
"d-s=1548241699; path=/; domain=.slack.com; secure; httponly",
"x=eo7res6xk440uh3keb6sggrzh.1548239853; expires=Wed, 23-Jan-2019 11:23:19 GMT; Max-Age=900; path=/; domain=.slack.com"
);
"Strict-Transport-Security" = (
"max-age=31536000; includeSubDomains; preload"
);
Vary = (
"Accept-Encoding"
);
Via = (
"1.1 5c49044a9bbc82066ce04ae597e1a6a7.cloudfront.net (CloudFront)"
);
"referrer-policy" = (
"no-referrer"
);
"x-amz-cf-id" = (
"jnczFrzoTMCmf-vZHd3M7jgYfKQEl0AEltH7fl74jZE144tGU2MvCw=="
);
"x-cache" = (
"Miss from cloudfront"
);
"x-frame-options" = (
SAMEORIGIN
);
"x-robots-tag" = (
"noindex,nofollow"
);
"x-via" = (
"haproxy-www-gd85"
);
"x-xss-protection" = (
0
);
} }
But when i am trying with non-private i am able to download and response is
-[DownloadHandler saveDirectoryPathForResponse:][L:124]response <NSHTTPURLResponse: 0x6040006244c0> { URL: https://files.slack.com/files-pri/T0B5PPLCX-FF7NT0NNA/download/chalte_chalte_-_pagalworld.org } { Status Code: 200, Headers {
"Accept-Ranges" = (
bytes
);
"Cache-Control" = (
"max-age=31536000, public"
);
Connection = (
"keep-alive"
);
"Content-Disposition" = (
"attachment; filename=\"Chalte Chalte - Pagalworld.org\"; filename*=UTF-8''Chalte%20Chalte%20-%20Pagalworld.org"
);
"Content-Length" = (
3763833
);
"Content-Type" = (
"audio/mpeg"
);
Date = (
"Wed, 23 Jan 2019 11:04:42 GMT"
);
Etag = (
"\"0c3a5aebdf8ab1acab4e098ccb77bc9a\""
);
Via = (
"1.1 b72519ee5ed84e4e3db077b5b7e93d38.cloudfront.net (CloudFront)"
);
"X-Amz-Cf-Id" = (
"aQ6auC2yu5RwLeYuEFyE3TT7tes36MTo5uGnTQ3vxXfGaZ2nAzxNJQ=="
);
"X-Backend" = (
"imgproxy-prod-pdx-lk25"
);
"X-Cache" = (
"Miss from cloudfront"
);
"X-Content-Type-Options" = (
nosniff
);
"X-Robots-Tag" = (
noindex
);
"X-Slack-Meta" = (
S3TA
);
} }
as you can see in private response which is different from non-private response and also content-disposition missing and you can also see response url is different. so in order to download the file even if the WKWebview is in private mode how to do that .
Any suggestions?
I'm having a problem using suggestedFilename with Hebrew file names.
I'm sending a response like this:
_fileName = [response suggestedFilename];
but for example if the NSURLResponse is something like this:
<NSHTTPURLResponse: ........> { URL: https://SOMETHINGSOMETHINGSOMETHING/A%D7%91%D7%93%D7%99%D7%A7%D7%94%20%D7%A2%D7%9D%20%D7%90%D7%95%D7%AA.txt } { Status Code: 200, Headers {
"Accept-Ranges" = (
bytes
);
Connection = (
"Keep-Alive"
);
"Content-Disposition" = (
"Attachment; filename=\"A\U00d7\U0091\U00d7\U0093\U00d7\U0099\U00d7\U00a7\U00d7\U0094 \U00d7\U00a2\U00d7\U009d \U00d7\U0090\U00d7\U0095\U00d7\U00aa.txt\""
);
"Content-Length" = (
0
);
"Content-Type" = (
"text/plain"
);
Date = (
"Sun, 04 Mar 2018 15:20:41 GMT"
);
Etag = (
"SOMETHING"
);
"Keep-Alive" = (
"timeout=2, max=100"
);
"Last-Modified" = (
"Wed, 28 Feb 2018 12:46:52 GMT"
);
Server = (
SOMETHING
);
Vary = (
"User-Agent"
);
"X-Frame-Options" = (
SAMEORIGIN
);
}
}
I'm getting in _filename : A××××§× ×¢× ××ת.txt
instead of : Aבדיקה עם אות.txt
any ideas?
I am using QuickBlox for my chatting app. The app turns black screen sometimes.
New LOG:
2014-01-24 01:54:42.302 Chat[5670:310b] Performing async request:
POST http://api.quickblox.com/session.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 5b25119abfa4c89aced5068a1b2d151b19b77e86;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"application_id" = 4354;
"auth_key" = yYBXmUnyvpYPMe5;
nonce = 125;
signature = a65c0971fa81ca8c79805b3ed4d7052e0ee5c059;
timestamp = 1390499682;
}
2014-01-24 01:54:42.352 Chat[5670:7b1b] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-01-24 01:54:42.352 Chat[5670:60b] chatDidFailWithError: 1
2014-01-24 01:54:42.353 Chat[5670:7b1b] QBChat/didDisconnect, error: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0x1565dbe0 {NSLocalizedDescription=Socket closed by remote peer}
2014-01-24 01:54:43.031 Chat[5670:60b] result is: <QBAAuthSessionCreationResult: 0x155830c0>
2014-01-24 01:54:43.032 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 524;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:41 GMT";
Etag = "\"3472cc7b5b8d9c8d5fff89fbfdb73931\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:41 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 2048340bfb6b9a87dd400a79a4b0a40c;
"X-Runtime" = "0.014610";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<session>
<_id>52e15761535c120d6e00523d</_id>
<application-id type="integer">4354</application-id>
<created-at type="datetime">2014-01-23T17:54:41Z</created-at>
<device-id type="integer">0</device-id>
<nonce type="integer">125</nonce>
<token>8564a56a8744464e61afdbb370c2d02cc3d940a6</token>
<ts type="integer">1390499682</ts>
<updated-at type="datetime">2014-01-23T17:54:41Z</updated-at>
<user-id type="integer">0</user-id>
<id type="integer">31413</id>
</session>
error:
2014-01-24 01:54:43.042 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/login.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 8564a56a8744464e61afdbb370c2d02cc3d940a6;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
login = hehe;
password = 12345678;
}
2014-01-24 01:54:43.741 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Length" = 590;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:41 GMT";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:41 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "202 Accepted";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = eab9d8949c044d1af3b0282222931428;
"X-Runtime" = "0.015342";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<blob-id type="integer" nil="true"/>
<created-at type="datetime">2014-01-23T15:47:06Z</created-at>
<email nil="true"/>
<external-user-id type="integer" nil="true"/>
<facebook-id nil="true"/>
<full-name nil="true"/>
<id type="integer">806773</id>
<last-request-at type="datetime" nil="true"/>
<login>hehe</login>
<owner-id type="integer">5464</owner-id>
<phone nil="true"/>
<twitter-id nil="true"/>
<updated-at type="datetime">2014-01-23T15:47:06Z</updated-at>
<website nil="true"/>
<user-tags nil="true"/>
</user>
error:
2014-01-24 01:54:43.749 Chat[5670:7b1b] -[QBChat loginWithUser:] -> Chat server endpoint: muc.chat.quickblox.com, User JID: 806773-4354#chat.quickblox.com
2014-01-24 01:54:43.770 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/push_tokens.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 8564a56a8744464e61afdbb370c2d02cc3d940a6;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"device[platform]" = iOS;
"device[udid]" = "D44DD5B1-A5B3-4E61-B761-A4DE8BB28F72";
"push_token[client_identification_sequence]" = 8efc776c0ea913f3cd8785f68bb4d7f3bb3a5ffcfde76ed1beab1181d8aae8af;
"push_token[environment]" = development;
}
2014-01-24 01:54:44.168 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/session.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 8564a56a8744464e61afdbb370c2d02cc3d940a6;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"application_id" = 4354;
"auth_key" = yYBXmUnyvpYPMe5;
nonce = 524;
signature = ce2521946486c0fb579a41f56e067661c059358b;
timestamp = 1390499684;
}
2014-01-24 01:54:44.169 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/session.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 8564a56a8744464e61afdbb370c2d02cc3d940a6;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"application_id" = 4354;
"auth_key" = yYBXmUnyvpYPMe5;
nonce = 484;
signature = 9da8fc95d9de0819b5f12ebefdf421e569adf2f3;
timestamp = 1390499684;
}
2014-01-24 01:54:44.417 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 272;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:42 GMT";
Etag = "\"36f956ca6271157cf23485a0efdd1770\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:42 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 6d05ab80975f4f00042664f0cbcc1896;
"X-Runtime" = "0.033340";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<push-token>
<client-identification-sequence>8efc776c0ea913f3cd8785f68bb4d7f3bb3a5ffcfde76ed1beab1181d8aae8af</client-identification-sequence>
<environment>development</environment>
<id type="integer">588770</id>
</push-token>
error:
2014-01-24 01:54:44.425 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/subscriptions.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 8564a56a8744464e61afdbb370c2d02cc3d940a6;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"notification_channels" = apns;
}
2014-01-24 01:54:44.780 Chat[5670:310b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 524;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:42 GMT";
Etag = "\"6fd90ffd8e3f5d10150f0acad6a0d46c\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:42 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = ce446bfab2d31c37e9e5ffc302603b8b;
"X-Runtime" = "0.015738";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<session>
<_id>52e15762535c12b64600503e</_id>
<application-id type="integer">4354</application-id>
<created-at type="datetime">2014-01-23T17:54:42Z</created-at>
<device-id type="integer">0</device-id>
<nonce type="integer">524</nonce>
<token>28ccd997f46ae70d9deec08d3e4a936881357ba7</token>
<ts type="integer">1390499684</ts>
<updated-at type="datetime">2014-01-23T17:54:42Z</updated-at>
<user-id type="integer">0</user-id>
<id type="integer">17423</id>
</session>
error:
2014-01-24 01:54:44.782 Chat[5670:60b] result is: <QBAAuthSessionCreationResult: 0x155825d0>
2014-01-24 01:54:44.788 Chat[5670:310b] Performing async request:
POST http://api.quickblox.com/login.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 28ccd997f46ae70d9deec08d3e4a936881357ba7;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
login = hehe;
password = 12345678;
}
2014-01-24 01:54:44.800 Chat[5670:60b] result is: <QBAAuthSessionCreationResult: 0x15589e90>
2014-01-24 01:54:44.796 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 524;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:42 GMT";
Etag = "\"1f4ecc5c5bded2167a761a907f23f3e3\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:42 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = c6da0e923aa3fc6d530f08d298c7332b;
"X-Runtime" = "0.014244";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<session>
<_id>52e15762535c12df80005377</_id>
<application-id type="integer">4354</application-id>
<created-at type="datetime">2014-01-23T17:54:42Z</created-at>
<device-id type="integer">0</device-id>
<nonce type="integer">484</nonce>
<token>0744438380a2cbfadf8e859b98d8bab319dd4383</token>
<ts type="integer">1390499684</ts>
<updated-at type="datetime">2014-01-23T17:54:42Z</updated-at>
<user-id type="integer">0</user-id>
<id type="integer">27111</id>
</session>
error:
2014-01-24 01:54:44.804 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/login.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 0744438380a2cbfadf8e859b98d8bab319dd4383;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
login = hehe;
password = 12345678;
}
2014-01-24 01:54:45.029 Chat[5670:380b] QBChat/didConnect
2014-01-24 01:54:45.059 Chat[5670:60b] Push notification subscribed
2014-01-24 01:54:45.058 Chat[5670:310b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 67;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:43 GMT";
Etag = "\"4f31ca96db448bb738a3923db737871d\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:43 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 9507e38031c78305d16b88a73e000557;
"X-Runtime" = "0.024274";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<nil-classes type="array"/>
error:
2014-01-24 01:54:45.430 Chat[5670:380b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Length" = 590;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:43 GMT";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:43 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "202 Accepted";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 4bfc06211bb0c0f97dd09f41ae92cff1;
"X-Runtime" = "0.015643";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<blob-id type="integer" nil="true"/>
<created-at type="datetime">2014-01-23T15:47:06Z</created-at>
<email nil="true"/>
<external-user-id type="integer" nil="true"/>
<facebook-id nil="true"/>
<full-name nil="true"/>
<id type="integer">806773</id>
<last-request-at type="datetime" nil="true"/>
<login>hehe</login>
<owner-id type="integer">5464</owner-id>
<phone nil="true"/>
<twitter-id nil="true"/>
<updated-at type="datetime">2014-01-23T15:47:06Z</updated-at>
<website nil="true"/>
<user-tags nil="true"/>
</user>
error:
2014-01-24 01:54:45.436 Chat[5670:811b] -[QBChat loginWithUser:] -> Chat server endpoint: muc.chat.quickblox.com, User JID: 806773-4354#chat.quickblox.com
2014-01-24 01:54:45.442 Chat[5670:310b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Length" = 590;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:43 GMT";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:43 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "202 Accepted";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 99a2c81bc8c28fddbcd7e3a134243ca3;
"X-Runtime" = "0.014854";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<blob-id type="integer" nil="true"/>
<created-at type="datetime">2014-01-23T15:47:06Z</created-at>
<email nil="true"/>
<external-user-id type="integer" nil="true"/>
<facebook-id nil="true"/>
<full-name nil="true"/>
<id type="integer">806773</id>
<last-request-at type="datetime" nil="true"/>
<login>hehe</login>
<owner-id type="integer">5464</owner-id>
<phone nil="true"/>
<twitter-id nil="true"/>
<updated-at type="datetime">2014-01-23T15:47:06Z</updated-at>
<website nil="true"/>
<user-tags nil="true"/>
</user>
error:
2014-01-24 01:54:45.448 Chat[5670:310b] -[QBChat loginWithUser:] -> Chat server endpoint: muc.chat.quickblox.com, User JID: 806773-4354#chat.quickblox.com
2014-01-24 01:54:45.464 Chat[5670:310b] Performing async request:
POST http://api.quickblox.com/push_tokens.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 0744438380a2cbfadf8e859b98d8bab319dd4383;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"device[platform]" = iOS;
"device[udid]" = "D44DD5B1-A5B3-4E61-B761-A4DE8BB28F72";
"push_token[client_identification_sequence]" = 8efc776c0ea913f3cd8785f68bb4d7f3bb3a5ffcfde76ed1beab1181d8aae8af;
"push_token[environment]" = development;
}
2014-01-24 01:54:46.107 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 272;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:44 GMT";
Etag = "\"36f956ca6271157cf23485a0efdd1770\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:44 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = a4319db211a2253aa7e98511d449e616;
"X-Runtime" = "0.042459";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<push-token>
<client-identification-sequence>8efc776c0ea913f3cd8785f68bb4d7f3bb3a5ffcfde76ed1beab1181d8aae8af</client-identification-sequence>
<environment>development</environment>
<id type="integer">588770</id>
</push-token>
error:
2014-01-24 01:54:46.110 Chat[5670:7b1b] Performing async request:
POST http://api.quickblox.com/subscriptions.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 0744438380a2cbfadf8e859b98d8bab319dd4383;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"notification_channels" = apns;
}
2014-01-24 01:54:46.266 Chat[5670:811b] -[QBChat xmppStreamDidAuthenticate:] -> user: 806773, supportsStartTLS: 1, isSecure: 0
2014-01-24 01:54:46.273 Chat[5670:310b] Performing async request:
GET http://api.quickblox.com/data/Post.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 0744438380a2cbfadf8e859b98d8bab319dd4383;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"sort_asc" = datetime;
}
2014-01-24 01:54:46.276 Chat[5670:310b] Performing async request:
GET http://api.quickblox.com/data/Contact.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 0744438380a2cbfadf8e859b98d8bab319dd4383;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"contact_id" = 806773;
}
2014-01-24 01:54:46.280 Chat[5670:310b] Performing async request:
GET http://api.quickblox.com/data/Contact.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = 0744438380a2cbfadf8e859b98d8bab319dd4383;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"user_identifier" = 806773;
}
2014-01-24 01:54:46.281 Chat[5670:310b] -[QBChat xmppStream:didSendIQ:] -> IQ: <iq type="get" id="5610067"><query xmlns="jabber:iq:roster"/></iq>
2014-01-24 01:54:46.282 Chat[5670:310b] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-01-24 01:54:46.533 Chat[5670:811b] -[QBChat xmppStream:didReceiveIQ:] -> <iq xmlns="jabber:client" id="5610067" type="result" to="806773-4354#chat.quickblox.com/tigase-20326"><query xmlns="jabber:iq:roster"/></iq>
2014-01-24 01:54:46.615 Chat[5670:60b] objects: (null)
2014-01-24 01:54:46.614 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 60;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:44 GMT";
Etag = "\"81779d89d928c6e830957d0cee5976fa\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:44 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "304 Not Modified";
"X-Rack-Cache" = miss;
"X-Request-Id" = 76bb535a5aa49e342dbf67fc1ae66950;
"X-Runtime" = "0.019699";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<data type="array"/>
error:
2014-01-24 01:54:46.620 Chat[5670:60b] objects: (null)
2014-01-24 01:54:46.622 Chat[5670:310b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 60;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:44 GMT";
Etag = "\"81779d89d928c6e830957d0cee5976fa\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:44 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "304 Not Modified";
"X-Rack-Cache" = miss;
"X-Request-Id" = ea19e51670b676c6b618662924052c99;
"X-Runtime" = "0.019819";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<data type="array"/>
error:
2014-01-24 01:54:46.703 Chat[5670:60b] Push notification subscribed
2014-01-24 01:54:46.703 Chat[5670:7b1b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 67;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:44 GMT";
Etag = "\"4f31ca96db448bb738a3923db737871d\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:44 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = e437212cb4bf3ecfc2170f85f9dbcbfb;
"X-Runtime" = "0.022193";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<nil-classes type="array"/>
error:
2014-01-24 01:54:46.929 Chat[5670:310b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 651;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 23 Jan 2014 17:54:44 GMT";
Etag = "\"bfdd8b18a9743a7d8aa5315262ec961d\"";
"QB-Token-ExpirationDate" = "2014-01-23 19:54:44 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "304 Not Modified";
"X-Rack-Cache" = miss;
"X-Request-Id" = 14ffdcfa6108ebb2614dd90721299f23;
"X-Runtime" = "0.020542";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<data type="array" class_name='Post' skip='0' limit='100'>
<Post>
<_id>52e13bd8535c1278a4004f83</_id>
<_parent_id nil="true"/>
<created-at type="integer">1390492632</created-at>
<datetime type="integer">20140123235708343</datetime>
<info>entity=post type=text post_identifier=20140123235708343a806749 datetime=20140123235708343 poster_id=806749 blob_id= text=post no</info>
<post_identifier>20140123235708343a806749</post_identifier>
<poster_id>806749</poster_id>
<updated-at type="integer">1390492632</updated-at>
<user-id type="integer">806749</user-id>
</Post>
</data>
error:
2014-01-24 01:54:46.931 Chat[5670:60b] objects: (
"
className:Post
createdAt:2014-01-23 15:57:12 +0000
updatedAt:2014-01-23 15:57:12 +0000
ID:52e13bd8535c1278a4004f83
parentID:(null)
userID:806749
fields:{\n datetime = 20140123235708343;\n info = \"entity=post type=text post_identifier=20140123235708343a806749 datetime=20140123235708343 poster_id=806749 blob_id= text=post no\";\n \"post_identifier\" = 20140123235708343a806749;\n \"poster_id\" = 806749;\n}
permissions:(null)"
)
2014-01-24 01:54:47.317 Chat[5670:811b] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
UPDATE 2:
When I enter background, then enter foreground, I will check if chat is logged in. using this condition:
[QBChat instance].isLoggedIn
(1)If it's logged in, i fetch several tables
(2)if not, I create a session and login again
My Guess:
Is it possible that after entering the background for a while, the session has been destroyed, while [QBChat instance].isLoggedIn still returns YES? If this is the case, then how can I test whether I can safely fetch tables?
The screen always turns black within 3 seconds after entering the foreground. I tried both iOS 6/7
Note: The screen goes black, but the app does not crash. because sendPresence timer still ticking every 15 seconds:
-[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
UPDATE 3:
I just catch a crash
UPDATE 4:
Device Log (Xcode organizer)
Date/Time: 2014-01-23 23:45:40.090 +0800
OS Version: iOS 7.0.2 (11A501)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x0000000027c1fff8
Triggered by Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x39411751 lookUpImpOrForward + 5
1 libobjc.A.dylib 0x3941172b lookUpImpOrNil + 23
2 libobjc.A.dylib 0x3940acb3 class_respondsToSelector + 31
3 libobjc.A.dylib 0x3941a059 -[NSObject respondsToSelector:] + 29
4 Chat 0x00141491 -[QBApplicationRedelegate applicationWillResignActive:] (QBApplicationRedelegate.m:111)
5 Chat 0x001414cd -[QBApplicationRedelegate applicationWillResignActive:] (QBApplicationRedelegate.m:112)
6 Chat 0x001414cd -[QBApplicationRedelegate applicationWillResignActive:] (QBApplicationRedelegate.m:112)
7 Chat 0x001414cd -[QBApplicationRedelegate applicationWillResignActive:] (QBApplicationRedelegate.m:112)
8 Chat 0x001414cd -[QBApplicationRedelegate applicationWillResignActive:] (QBApplicationRedelegate.m:112)
I solved the question by registering push notification in ChatDidLogin instead of user did login delegate method.
the problem is that login use will return success even use has already logged in, which will register push notification twice. However, chat will fail if already logged in.
My app constantly checks whether the server is logged in by
+ (BOOL)isServerLoggedIn {
return [QBChat instance].isLoggedIn;
}
if not logged in, I create session with delegate again, which will then log user in upon success, and then log chat in upon success.
Edit: there is a problem with this design:
What if [QBChat instance].isLoggedIn is true but QBUser is not logged in??
How to check whether QBUser is logged in?
You can be separately logged in to Chat and to REST services.
To check if QBUser is logged in - just create a separate variable and set it to YES in delegate:
// QuickBlox queries delegate
- (void)completedWithResult:(Result *)result{
if(result.success){
// User Login
if([result isKindOfClass:QBUUserLogInResult.class]){
self.userLoggedIn = YES;
}
}
}
EDIT: I've found the solution.
The problem is that QBUsers:signUp doesn't perform user login. So you (and me) should do QBUsers:logIn after QBUsers:signUp
At first I login my user or signup, if user doesn't exist. My code:
qbUser = [QBUUser user];
qbUser.fullName = #"some name";
qbUser.login = #"40118285";
qbUser.password = #"worldvideovoyage";
...
[QBUsers logInWithUserLogin:qbUser.login password:qbUser.password delegate:self];
If user doesn't exist yet I perform singing up the user:
-(void)completedWithResult:(Result *)result
{
if(!result.success) {
ASLog(#"%#", result.errors);
}
if([result isKindOfClass:QBUUserLogInResult.class]) {
if(result.success) {
QBUUserLogInResult *res = (QBUUserLogInResult*)result;
qbUser = res.user;
ASLog(#"LogIn user %# completed", qbUser.email);
[self.params loadWithUserID:qbUser.ID];
} else {
// we have to signup firstly
ASLog(#"Signup user %#", qbUser.login);
[QBUsers signUp:qbUser delegate:self];
}
} else if([result isKindOfClass:QBUUserResult.class]) {
if(result.success) {
QBUUserResult *res = (QBUUserResult*)result;
qbUser = res.user;
ASLog(#"Signup user %# completed", qbUser.email);
[self.params saveWithUserID:qbUser.ID];
[[NSNotificationCenter defaultCenter] postNotificationName:nCHANGE_USER object:self];
} else {
// signup fails
ASLog(#"ERROR: signup fail!");
}
}
}
After that I have in console:
2013-09-10 13:49:42.109 DimChat[48347:1b27] Request finished, response:
RestResponse:
------
<QBASIHTTPRequest: 0xe275400>
headers:{
"Access-Control-Allow-Headers" = "QB-Token,QuickBlox-REST-API-Version";
"Access-Control-Allow-Origin" = "*";
"Access-Control-Request-Method" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = Close;
"Content-Length" = 623;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Tue, 10 Sep 2013 09:49:39 GMT";
Etag = "\"9973e1c39deddfd236cab1a0de3e4b38\"";
Location = "http://api.quickblox.com/users/503563";
"QB-Token-ExpirationDate" = "2013-09-10 11:49:39 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 6c8eddea8a6f7b6c03e6eb02d40472a3;
"X-Runtime" = "0.083159";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:<?xml version="1.0" encoding="UTF-8"?>
<user>
<blob-id type="integer" nil="true"/>
<created-at type="datetime">2013-09-10T09:49:39Z</created-at>
<email nil="true"/>
<external-user-id type="integer" nil="true"/>
<facebook-id nil="true"/>
<full-name>ÐаÑилий ÐакаÑов</full-name>
<id type="integer">503563</id>
<last-request-at type="datetime" nil="true"/>
<login>40118285</login>
<owner-id type="integer">4855</owner-id>
<phone nil="true"/>
<twitter-id nil="true"/>
<updated-at type="datetime">2013-09-10T09:49:39Z</updated-at>
<website nil="true"/>
<user-tags nil="true"/>
</user>
error:
2013-09-10 13:49:42.110 DimChat[48347:c07] -[ASUser completedWithResult:] [Line 262] Signup user (null) completed
And then I try to create QBCOCustomObject:
co = [QBCOCustomObject customObject];
co.className = #"Settings";
co.userID = userID;
co.fields[#"goal"] = [NSNumber numberWithInt:_goal];
// ... init other fields of custom object
[QBCustomObjects createObject:co delegate:self];
And I get an error:
2013-09-10 13:50:11.135 DimChat[48347:cb0f] Request finished, response:
RestResponse:
------
<QBASIHTTPRequest: 0xe275400>
headers:{
"Access-Control-Allow-Headers" = "QB-Token,QuickBlox-REST-API-Version";
"Access-Control-Allow-Origin" = "*";
"Access-Control-Request-Method" = "*";
"Cache-Control" = "no-cache";
Connection = Close;
"Content-Length" = 97;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Tue, 10 Sep 2013 09:50:08 GMT";
"QB-Token-ExpirationDate" = "2013-09-10 11:49:39 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "422 Unprocessable Entity";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 081ee974feacc97e8af6a2c53e1795da;
"X-Runtime" = "0.031358";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Forbidden. Need user.</error>
</errors>
I'm pretty sure that I have valid QBUUser and I performed login. But why I have this error?
I've found the solution.
The problem is that QBUsers:signUp doesn't perform user login. So you (and me) should do QBUsers:logIn after QBUsers:signUp