APNS:错误域= NSCocoaErrorDomain代码= 3840 [英] APNS :Error Domain = NSCocoaErrorDomain Code=3840

查看:170
本文介绍了APNS:错误域= NSCocoaErrorDomain代码= 3840的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向服务器注册设备数据,以获取推送通知.代码在这里,

Im registering device data with the server, to get push notification. Here it goes the code,

[NSURLConnection sendAsynchronousRequest: request
                                           queue: _postQueue
                               completionHandler: ^(NSURLResponse *response, NSData *responseData, NSError *connectionError) {
                                   if (connectionError) {
                                       //
                                   } else {
                                      NSError *error = nil;
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData: responseData options: NSJSONReadingMutableContainers error: &error];
                                   }
                               }];

我收到错误消息

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x17057f60 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

有人可以帮忙解决此问题吗?

Can someone please help to fix the issue?

推荐答案

错误消息告诉您确切的问题所在:来自服务器的响应不包含有效的JSON.从技术上讲,JSON必须以数组或对象(字典)开头.无论您的服务器返回的是什么.您可以通过使用NSJSONReadingAllowFragments选项强制使用JSON.

The error message is telling you exactly what's wrong: the response from your server doesn't contain valid JSON. Technically, JSON must start with either an array or an object (dictionary). Whatever your server is returning isn't. You can force the JSON to be consumed regardless by using the NSJSONReadingAllowFragments option.

如果使用该选项后,您仍然 出现错误,则您的服务器可能返回格式错误的JSON(或完全没有JSON).您为什么不查看服务器中的日志以准确了解您发回的邮件呢?

If after using that option you're still getting errors then your server is probably returning malformed JSON (or no JSON at all). Why don't you take a look at the logs from your server to see exactly what you're sending back?

这篇关于APNS:错误域= NSCocoaErrorDomain代码= 3840的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆