If I'm using this below code
aDownloadTask = [self.backgroundSession downloadTaskWithURL:aRemoteURL];
Desc of above code:
When I started download by using downloadTaskWithURL It’s return expectedContentLength negative(-1) But that time resume data getting perfectly.
Another one is
For solved above problem I'm using this below code
NSMutableURLRequest *aURLRequest = nil;
aURLRequest = [[NSMutableURLRequest alloc] initWithURL:aRemoteURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[aURLRequest setHTTPMethod:#"POST"];
[aURLRequest setValue:#"identity" forHTTPHeaderField:#"Accept-Encoding"];
aDownloadTask=[self.backgroundSession downloadTaskWithRequest:aURLRequest];
Desc of above code: Using above code expectedContentLength getting perfectly. But issue is the when pause downloading resume data nil every time.
Thats why my downloading start from beginning and not from that point when I pause.
Thanks in advance
Please , remove this below line from your code and try. Your resume data will getting perfectly.
[aURLRequest setHTTPMethod:#"POST"];
Related
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:tempURL]] autorelease];
[request setValue:encryptedValue forHTTPHeaderField:#"EncString"];
I could spot all other headers in the request but this specific header is missing, can any one let me know what could be the reasons.
I have tried the following code:
NSString *tempURL = #"https://stackoverflow.com/questions/50701101/unable-to-add-a-header-to-nsmutablerequest";
NSString *encryptedValue = #"whatever_that_has_no_special_characters_or_values_that_would_make_you_think_it_is_relevant_to_reproduce_this_issue";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:tempURL]];
[request setValue:encryptedValue forHTTPHeaderField:#"EncString"];
NSLog(#"%#", request.allHTTPHeaderFields);
The output is:
{
EncString = "whatever_that_has_no_special_characters_or_values_that_would_make_you_think_it_is_relevant_to_reproduce_this_issue";
}
which looks good. There is no reason to suspect the code you provided is responsible for the issue. Maybe you should check one of the following:
Is encryptedValue truly a valid object to be placed into header (is string, not too long, no very special characters)
Is the object you are printing really this specific request (printing NSLog(#"%p", request); returns same result)
In no place in this object a herder is being removed (if nothing else subclass NSMutableURLRequest and override relevant methods to track what is going on)
If none of these work create a post with additional details on what you have done, where are you checking these headers and "could spot all other headers".
I am trying to upload multiple documents (say: images and videos) at the same time with hitting on single API. The API is developed in Ruby ON Rails. I am trying to upload documents in iPhone using ASIHTTP methods. Here is the screenshot of getpostman. On getpostman, It is working fine. Multiple documents are working fine but when I am using same API in xcode then its giving me error.
What I have done till now is, I have used two ways.
1.) Sending multiple documents's data using dictionaries. Here is the code snippet:-
[self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:#"http://onepgr.com/docs/create6_api"]]];
[request setPostValue:#"11" forKey:#"clientname"];
[request setPostValue:#"1" forKey:#"onepgr_apicall"];
[request setPostValue:pageID forKey:#"page_id"];
//[request setPostValue:#"true" forKey:#"multiple"];
//[request setPostValue:array forKey:#"doc"];
[request setPostValue:#"" forKey:#"passcode"];
[request setPostValue:#"33" forKey:#"clientappkey"];
[request setPostValue:#"22" forKey:#"clientappid"];
[request setTimeOutSeconds:20];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[request setShouldContinueWhenAppEntersBackground:YES];
#endif
[request setUploadProgressDelegate:progressView];
[request setDelegate:self];
[request setDidFailSelector:#selector(uploadFailed:)];
[request setDidFinishSelector:#selector(uploadFinished:)];
//Uncomment For Multiple Upload
for (int i = 0; i<self.chosenImages.count; i++)
{
UIImage *img = [self.chosenImages objectAtIndex:i];
NSString *str = [NSString stringWithFormat:#"Image_File_%d.png",i+1];
strFileName = str;
strContentType = #"image/png";
fileData = UIImageJPEGRepresentation(img, 1.0);
if (i == 0)
[request setData:fileData withFileName:strFileName andContentType:strContentType forKey:#"doc"];
else
[request addData:fileData withFileName:strFileName andContentType:strContentType forKey:#"doc"];
}
2.) I have tried sending the data in for loop as well. But nothing worked for me.
Looking forward to have some answers that can help me out.
Thanks,
Nikhil
Use http://www.charlesproxy.com/ to check the differences between the 2 requests
My personal bet is that the problem is that you are setting the image data within the loop always to the same key.
I need to send a image to server with Url the url looks as below
http://somewebsite.com:8080/app/api/fappname/newUser/1/Delhi481/cct/12 dk/11588/kmkr/72579/Los/TM/8:00/13:00/28.6100/77.2300/foto1.jpg/null
they asked me to send image in place of foto1.jpg, the code that now i'm using is as below i am sending null inplace of image i'm getting response. can any one send me how to send the image in this url.
NSString *str = [NSString stringWithFormat:#"http://someurl.com:8080/app/api/kkknnmm/newUser/1/%#/%#/%#/%#/%#/%#/%#/TM/%#/%#/%#/%#/%#/%#/%#",[inSchoolName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],#"kktt",[inAddressStreet stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],inAddressNo,inAddressState,inZipCode,[inNeighbourhood stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[arrivalHR stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[endingHr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],inlat,inlong,inImg1,inImg2,inImg3];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:str]];
NSLog(#"Login Url:%#",str);
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
can any one please help me.
Well your Api Is expecting binary data, I would suggest you to go through these links.
I hope they Will Help you.
Have A look at this And this
I use IOS7
I start download and i lock screen, and i open screen. My program is shutdown...
Is there some can help me ?
This is major code:
init download url:
NSURL *url = [NSURL URLWithString:dictionaryUrl];
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
set ASIHTTPRequest delegate:
request.delegate = self;
init file save path:
NSString *savePath = [path stringByAppendingPathComponent:name];
bool b=[ fileManager createFileAtPath :savePath contents : nil attributes : nil ];
if (b){
fileHandle=[ NSFileHandle fileHandleForWritingAtPath :savePath];
}
[request setAllowResumeForFileDownloads:NO];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestDone:)];
[request setDidFailSelector:#selector(requestWentWrong:)];
[request setDataReceivedBlock :^( NSData * data){
[fileHandle seekToEndOfFile ];
[fileHandle writeData :data];
[ label setText :[ NSString stringWithFormat : #"downloading...%.1f %%" , process . progress * 100 ]];
}];
[request setDownloadProgressDelegate:process];
add to ASINetworkQueue:
[self.netWorkQueue addOperation:request];
relase request:
[request release];
First, you need to enable the request to run at background. add this :
[request setShouldContinueWhenAppEntersBackground:YES];
for quick task it's possible, works like charm. but for long running task, just like you wanted, to keep continue download, you need to add a bit code, to enable this request from being terminated because run too long.
I've answered question for location update by adding timer and fire API every x seconds indefinitely. using UIBackgroundTaskIdentifier and NSTimer. This should give you an idea. should be same concept of what you are doing.
How do I get a background location update every n minutes in my iOS application?
When your screen gets lock your app goes to background.You can perform tasks for a limited time after your application is directed to go to the background, but only for the duration provided. Running for longer than this will cause your application to be terminated. See the "Completing a Long-Running Task in the Background" section of the iOS Application Programming Guide for how to go about this.
For iOS7 you can check this link https://stackoverflow.com/a/19355437/1372368.
And the code snippet to run task in background you can find various links like:How to keep an iPhone app running on background fully operational
I am currently developing an iOS application and am implementing the Box.Net SDK. I have gotten everything to work except the ability to move files around, which is not a native feature of the SDK. I am trying to twist my way through it.
If you are familiar with the structure of Box.Net, each file/folder has an ID number for itself, and an ID its parent. From what I understand if I want to move a file, I am supposed to change the parent ID number on the file which will point it to the new location. I can't seem to get it to work properly though. My application seems to keep crashing.
This is what I have so far, generalized.
BoxObject *boxObject = [[[Box objectWithID:(ID#ofParent)] children] objectAtIndex:i];
[boxObject parent].boxID = 0; // <-- Problem (causes crash)
I also tried this.
[boxObject setParent:[Box folderWithID:[BoxID numberWithInt:i]]];
The boxObject variable is the file that I want to move. I am setting its parent ID equal to 0, which is supposed to be the root folder. However, my application crashes when I try to reassign the parent ID for the file. Any ideas on how to successfully move files/folders? Any help is much appreciated! Thanks in advance!
Okay. I suppose there wasn't a way to do fix this in-house with the SDK. So, I had to send out an external PUT request. I used the following code to handle moving files.
- (void)moveItem:(BoxObject *)object toParentFolderWithID:(BoxID *)parentID
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://api.box.com/2.0/files/%#", object.boxID]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"PUT"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *auth = [NSString stringWithFormat:#"BoxAuth api_key=%#&auth_token=%#",[Box boxAPIKey],[defaults objectForKey:#"box-api-auth-token"]];
NSString *payload = [NSString stringWithFormat:#"{\"parent\": {\"id\": %#}}", parentID];
[request setHTTPBody:[NSMutableData dataWithData:[payload dataUsingEncoding:NSUTF8StringEncoding]]];
[request setValue:auth forHTTPHeaderField:#"Authorization"];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
[connection start];
}
Just as a reminder if you are new to the Box SDK, you will most likely need to update/refresh the data after moving the files. If not handled, your application could crash if the file doesn't exist. Hope this helps to anyone was not sure about this.