nsurlsessiondatatask


How to return a value with NSURLSessionDataTask? xcode


Hello everybody!
I'm only have 3 weeks with NSURLSessionDataTask, but allways xcode returns a error.
[3] (null) #"NSLocalizedDescription" : #"Request failed: unacceptable
content-type: application/json"
The main function is this:
+ (Document * ) getDocumentInfo: (NSString *) grupo documento:(NSString *) documento {
BDBOAuth1SessionManager *sesion = [manager getSessionManager];
sesion.responseSerializer = [AFHTTPResponseSerializer new];
sesion.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:#"application/json", #"text/json", #"text/plain",#"text/html", nil];
static NSMutableDictionary *json;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSString *timelinePath = [NSString stringWithFormat:#"/api/v1/rest/groups/%#/document/%#",grupo,documento];
static NSString *check;
sesion.completionQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
AFHTTPRequestOperation *operation = [sesion GET:timelinePath
parameters:#{}
success:^(NSURLSessionDataTask *task, id requestReply) {
NSString *requestReply2 = [[NSString alloc] initWithBytes:[requestReply bytes] length:[requestReply length] encoding:NSUTF8StringEncoding];
NSData *data = [requestReply2 dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSError * error;
json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];
if (![requestReply2 isEqualToString:#""]) {
if ([[json objectForKey:#"result"] isEqualToString:#"OK"]) {
check = #"YES";
}
}
dispatch_semaphore_signal(semaphore);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
//nslo(nil, error);
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
if ([check isEqualToString:#"YES"]) {
return[Document generateDocument:[json objectForKey:#"object"]];
//return fichero;
}else{
return nil;
}
}
The main objective is atack API of Zyncro and this return a information in json.
The function of generate object Document is:
+ (Document * ) generateDocument: (NSDictionary *) itemDic {
Document *d = [[Document alloc] init];
d.appIdCreator = ([itemDic valueForKey:#"appIdCreator"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"appIdCreator"];
d.descript = ([itemDic valueForKey:#"descript"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"descript"];
d.urn = ([itemDic valueForKey:#"urn"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"urn"];
d.groupType = ([itemDic valueForKey:#"groupType"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"groupType"];
d.payload = ([itemDic valueForKey:#"payload"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"payload"];
d.link = ([itemDic valueForKey:#"link"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"link"];
d.lastWriteTime = ([itemDic valueForKey:#"lastWriteTime"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"lastWriteTime"];
d.appIdLastWriteUser = ([itemDic valueForKey:#"appIdLastWriteUser"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"appIdLastWriteUser"];
d.relativePath = ([itemDic valueForKey:#"relativePath"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"relativePath"];
d.size = ([itemDic valueForKey:#"size"] == (id)[NSNull null])? -1 : [[itemDic valueForKey:#"size"] integerValue];
d.creationTime = ([itemDic valueForKey:#"creationTime"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"creationTime"];
d.groupUrn = ([itemDic valueForKey:#"groupUrn"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"groupUrn"];
d.lastVersion = ([itemDic valueForKey:#"lastVersion"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"lastVersion"];
d.versionsCount = ([itemDic valueForKey:#"versionsCount"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"versionsCount"];
d.name = ([itemDic valueForKey:#"name"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"name"];
d.documentType = ([itemDic valueForKey:#"documentType"] == (id)[NSNull null])? -1 : [[itemDic valueForKey:#"documentType"] integerValue];
// MEMBER
//d.creatorMember = ([itemDic valueForKey:#"creatorMember"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"creatorMember"];
d.creatorMember= [Member addMember:[itemDic valueForKey:#"creatorMember"]];
d.lastWriteMember= [Member addMember:[itemDic valueForKey:#"lastWriteMember"]];
//d.lastWriteMember = ([itemDic valueForKey:#"lastWriteMember"] == (id)[NSNull null])? #"" : [itemDic valueForKey:#"lastWriteMember"];
return d;
}
my question is why if i put acceptable content: application/json because the error is in application/json thank you guys
thanks for all

Related Links

AFHTTPSessionManager post request
How to return a value with NSURLSessionDataTask? xcode

Categories

HOME
algorithm
embedded
localization
adal
dns
apache-jena
css3
mysql-workbench
sitecore
solaris
error-handling
switch-statement
rds
limit
echo
data-visualization
banner
jtextpane
trac
teechart
mql5
dkim
vimdiff
datastage
intercom
comsol
scrolltop
parameter-passing
gruntfile
null-pointer
microsoft-ocr
froala
tiki-wiki
beautifier
pic32
quantlib
testbed
quickfixj
android-gridview
modalviewcontroller
baidu-map
mnist
openalpr
demo
doc
laravel-elixir
importerror
nanoc
lampp
cnc
globalize
baidu
rxtx
cubism.js
xcode-server
async.js
signalr.client
xdoclet
firebase-security
swizzling
libav
lazybones
vacuum
wso2greg
linked-tables
keyup
git-ftp
cryptographichashfunction
ejb-2.x
at-job
packet-sniffers
human-computer-interface
dct
cfcache
ora-06550
eclipse-kepler
away3d
chart-director
bjyauthorize
midlet
monotouch.dialog
usertype
box2d-iphone
codebase
timertask
jqueryform
web-garden
cfwindow
data-mapping
sqlobject
appliance
great-circle

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App