how to increment month and year from calendar in ios - ios

i am trying to increment date and year from calendar, but it is incrementing only one value which means (it is incrementing from jan to feb, but it is not incrementing after feb) my requirement is to incrementing upto 12 month and also simultaneously year has to increment. could you please tell me how to resolve this issue this is my code
- (IBAction)right:(id)sender {
[datearray removeAllObjects];
NSCalendar *cal = [NSCalendar currentCalendar];
date = [cal dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:[NSDate date] options:0];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM YYYY"];
NSString *stringFromDate = [formatter stringFromDate:date];
yar.text=stringFromDate;
NSString *y1=yar.text;
NSArray * arr = [y1 componentsSeparatedByString:#" "];
NSString *m=arr[0];
NSString *yy=arr[1];
spinner = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
spinner.mode = MBProgressHUDModeCustomView;
[spinner setLabelText:#"Loading....."];
[spinner setLabelFont:[UIFont systemFontOfSize:15]];
[spinner show:YES];
//[self.coutweek setText:[NSString stringWithFormat:#"%d",week]];
NSString *urlString = [NSString stringWithFormat:#"http://edvancepreschoolsadminpanel.com/viverobranch/json/json_lunch.php?key=agile89rise98&food=%#&month=%#&year=%#&username=%#",scl,m,yy,temp];
NSLog(#"the url string==%#",urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(#"the str==%#",jsonString);
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSLog(#"%#",results);
luncharray = [[NSMutableArray alloc]init];
NSArray *array=[results objectForKey:#"lunch_menu"];
for (int i=0; i<[array count]; i++) {
NSString *dat =[[array objectAtIndex:i]objectForKey:#"date"];
NSString *mon =[[array objectAtIndex:i]objectForKey:#"month"];
NSString *yea =[[array objectAtIndex:i]objectForKey:#"year"];
NSString *luh =[[array objectAtIndex:i]objectForKey:#"food"];
NSString *tim =[[array objectAtIndex:i]objectForKey:#"time"];
ipadlunch *myimg =[[ipadlunch alloc]initWithdat:dat andmon:mon andyea:yea andlunch:luh andtime:tim];
NSLog(#"%#",myimg);
[luncharray addObject:myimg];
// NSLog(#"the field==%#",videoarray1);
}

Related

POST some text and images with time to PHP service in Objective -C

Made 3 view controllers. FIRST with the name vc1 and second with vc2 and third with vc3. in vc1 there is some textfield data and in vc2 there are some image views and buttons under it, these images first to convert to base64.Third vc it also have some text field now i want to submit all the data from textfield of vc1 and vc3 and all the images from vc2 with time in milliseconds to a php web service. I have written some code but I'm not getting any response. can anyone help me plzz. My code is:
enter code here`NSString *dateString1 = #"16-05-2017 14:35";
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat:#"dd-MM-yyyy HH:mm"];
NSDate *dateFromString1 = [[NSDate alloc] init];
dateFromString1 = [dateFormatter1 dateFromString:dateString1];
NSTimeInterval timeInMiliseconds1 = [dateFromString1 timeIntervalSince1970]*1000;
NSString *timestamp1=[NSString stringWithFormat:#"%f",timeInMiliseconds1];
NSLog(#"time in mililsecond is %.00f",timeInMiliseconds1);
NSString *dateString2 = #"16-05-2017 14:35";
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:#"dd-MM-yyyy HH:mm"];
NSDate *dateFromString2 = [[NSDate alloc] init];
dateFromString2 = [dateFormatter2 dateFromString:dateString2];
NSTimeInterval timeInMiliseconds2 = [dateFromString2 timeIntervalSince1970]*1000;
NSString *timestamp2=[NSString stringWithFormat:#"%f",timeInMiliseconds2];
NSLog(#"time in mililsecond is %.00f",timeInMiliseconds2);
NSString *dateString3 = #"16-05-2017 14:35";
NSDateFormatter *dateFormatter3 = [[NSDateFormatter alloc] init];
[dateFormatter3 setDateFormat:#"dd-MM-yyyy HH:mm"];
NSDate *dateFromString3 = [[NSDate alloc] init];
dateFromString3 = [dateFormatter3 dateFromString:dateString3];
NSTimeInterval timeInMiliseconds3 = [dateFromString3 timeIntervalSince1970]*1000;
NSString *timestamp3=[NSString stringWithFormat:#"%f",timeInMiliseconds3];
NSLog(#"time in mililsecond is %.00f",timeInMiliseconds3);
NSString *dateString4 = #"16-05-2017 14:35";
NSDateFormatter *dateFormatter4 = [[NSDateFormatter alloc] init];
[dateFormatter4 setDateFormat:#"dd-MM-yyyy HH:mm"];
NSDate *dateFromString4 = [[NSDate alloc] init];
dateFromString4 = [dateFormatter4 dateFromString:dateString4];
NSTimeInterval timeInMiliseconds4 = [dateFromString4 timeIntervalSince1970]*1000;
NSString *timestamp4=[NSString stringWithFormat:#"%f",timeInMiliseconds4];
NSLog(#"time in mililsecond is %.00f",timeInMiliseconds4);
NSString *dateString5 = #"16-05-2017 14:35";
NSDateFormatter *dateFormatter5 = [[NSDateFormatter alloc] init];
[dateFormatter5 setDateFormat:#"dd-MM-yyyy HH:mm"];
NSDate *dateFromString5 = [[NSDate alloc] init];
dateFromString5 = [dateFormatter5 dateFromString:dateString5];
NSTimeInterval timeInMiliseconds5 = [dateFromString5 timeIntervalSince1970]*1000;
NSString *timestamp5=[NSString stringWithFormat:#"%f",timeInMiliseconds5];
NSLog(#"time in mililsecond is %.00f",timeInMiliseconds5);
NSString *dateString6 = #"16-05-2017 14:35";
NSDateFormatter *dateFormatter6 = [[NSDateFormatter alloc] init];
[dateFormatter6 setDateFormat:#"dd-MM-yyyy HH:mm"];
NSDate *dateFromString6 = [[NSDate alloc] init];
dateFromString6 = [dateFormatter6 dateFromString:dateString6];
NSTimeInterval timeInMiliseconds6 = [dateFromString6 timeIntervalSince1970]*1000;
NSString *timestamp6=[NSString stringWithFormat:#"%f",timeInMiliseconds6];
NSLog(#"time in mililsecond is %.00f",timeInMiliseconds6);
NSString *post = [NSString stringWithFormat:#"name=%#&email=%#&phone=%#&propertytitle=%#&propertyfor=%#&propertytype=%#&propertyprice=%#&propertyavail=%#&landarea=%#&noofrooms=%#&noofbathrooms=%#&nooffloors=%#&description=%#&structureofproperty=%#&structureofflooring=%#&wallsstructure=%#&doorsstructure=%#&=electricalstructure=%#&location=%#&country=%#&city=%#&imgurl1=%#&timestamp1=%#&imgurl2=%#&timestamp2=%#&imgurl3=%#&timestamp3=%#&imhurl4=%#&timestamp4=%#&imgurl5=%#&timestamp5=%#&imgurl6=%#&timestamp6%#",_name.text,_email.text,_Phone.text,_propertytitle,_propertyfor,_propertytype,_propertyprice,_propertyavail,_landarea,_noofrooms,_noofbathrooms,_nooffloors,self.description,_structureofproperty,_structureofflooring,_wallsstructure,_doorsstructure,_electricalstructure,_Location,_but1.titleLabel.text,_but2.titleLabel.text,_imgurl1,timestamp1,_imgurl2,timestamp2,_imgurl3,timestamp3,_imgurl4,timestamp4,_imgurl5,timestamp5,_imgurl6,timestamp6];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:#" my url"]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(#"requestReply: %#", requestReply);
resume];

Whenever I upload video the page getting hang

I am doing a chatting app with JSQmessagecontroller library every thing is working fine but whenever I upload video the page get hang.
I am doing a chatting app with JSQmessagecontroller library every thing is working fine but whenever I upload video the page get hang.
- (id<JSQMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView messageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString * chat = [[DataArray objectAtIndex:indexPath.row] objectForKey:#"Message"];
NSString * imageurl = [[DataArray objectAtIndex:indexPath.row] objectForKey:#"media"];
if (chat == nil)
{
// NSString *responseString = [[NSString alloc]initWithData:webdata encoding:NSUTF8StringEncoding];
if ([imageurl rangeOfString:#".jpg"].location == NSNotFound) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"Video is Loading....");
image1 =[[UIImageView alloc]init];
MPMoviePlayerController *player1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:imageurl]];
[player1 stop];
[self thumbnailImageFromURL:[NSURL URLWithString:imageurl]];
JSQPhotoMediaItem *vitem;
vitem = [[JSQPhotoMediaItem alloc] initWithImage:thumbnailImage];
// NSString * date12=[[DataArray objectAtIndex:indexPath.row] objectForKey:#"date"];
NSString *dateString = [[DataArray objectAtIndex:indexPath.row] objectForKey:#"date"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd-MM-YY HH:mm a"];
dateFromString = [[NSDate alloc] init];
dateFromString=[dateFormatter dateFromString:dateString];
messageForRow = [[JSQMessage alloc] initWithSenderId:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"UserId"] senderDisplayName:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"Name"]date:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"date"] media:vitem] ;
// JSQPhotoMediaItem *vitem = [[JSQPhotoMediaItem alloc] initWithImage:thumbnailImage];
});
});
}
else
{
image1 =[[UIImageView alloc]init];
UIImage *im=[[UIImage alloc]init];
[image1 sd_setImageWithURL:[NSURL URLWithString:imageurl]
placeholderImage:nil];
im=image1.image;
JSQPhotoMediaItem *item = [[JSQPhotoMediaItem alloc] initWithImage:im];
NSString *dateString = [[DataArray objectAtIndex:indexPath.row] objectForKey:#"date"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd-MM-YY HH:mm a"];
//dateFromString = [[NSDate alloc] init];
dateFromString=[dateFormatter dateFromString:dateString];
messageForRow = [[JSQMessage alloc] initWithSenderId:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"UserId"] senderDisplayName:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"Name"] date:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"date"] media:item] ;
}
}
else
{
messageForRow = [[JSQMessage alloc] initWithSenderId:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"UserId"] senderDisplayName:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"Name"] date:[[DataArray objectAtIndex:indexPath.row] objectForKey:#"date"] text: [[DataArray objectAtIndex:indexPath.row] objectForKey:#"Message"]] ;
}
return messageForRow;
}

Downloading JSON in iOS and using it to draw the UI

I'm relatively new to iOS development and my current project requires me to Connect to a website through a Rest API, and use JSON Objects received from the site to populate a Custom UITableViewController which I have implemented. I have been able to download the information and get it to display on the table properly, but this requires me to enter the page which starts the download, then leave the page and enter it again, upon which all of the cells are populated. How can I make my app load this information without leaving the page?
My Custom UITableViewClass contains the following methods:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *chuckFranklinConnection = #"http://chuckfranklinlaw.com/wp-json/posts?type=tribe_events";
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL: [NSURL URLWithString:chuckFranklinConnection]
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error){
//Complete Data Handling from Chuckfranklinlaw.com Here
NSString *responseData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *e = nil;
jsonArray = [NSJSONSerialization JSONObjectWithData: data options:NSJSONReadingMutableContainers error: &e];
if(!jsonArray) {
NSLog(#"Error parsing JSON: %#", e);
}else {
NSLog(#"Begin Successful Parse Readout -----------");
for(NSDictionary *item in jsonArray) {
NSLog(#"Item: %#", item);
}
}
}]
resume];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<##"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
EventTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"EventsCell"];
if(cell == nil) {
cell = [[EventTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"EventsCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
//Formatting for each Cell Title
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = [[jsonArray objectAtIndex:indexPath.row] objectForKey: #"title"];
//Formatting for each Cell Detail
NSString *startDate = [[jsonArray objectAtIndex:indexPath.row] objectForKey: #"StartDate"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:startDate];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
cell.data = [[jsonArray objectAtIndex:indexPath.row] objectForKey:#"ID"];
cell.detailTextLabel.text = [dateFormatter stringFromDate:date];
//Work On Implementing Image View for App in this section
NSDictionary *imageInfo = [[jsonArray objectAtIndex:indexPath.row] objectForKey:#"featured_image"];
NSDictionary *attachmentMeta = [imageInfo objectForKey:#"attachment_meta"];
NSDictionary *sizes = [attachmentMeta objectForKey:#"sizes"];
NSDictionary *thumbnail = [sizes objectForKey:#"thumbnail"];
NSString *url = [thumbnail objectForKey:#"url"];
NSLog(url);
UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
cell.imageView.image = image;
return cell;
[cell setNeedsDisplay];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"showEventDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *detailView = segue.destinationViewController;
NSString *contentString = [[jsonArray objectAtIndex:indexPath.row] objectForKey:#"content"];
//The Following code mutates the HTML Strings recieved from the server into NSStrings for displaying
contentString = [contentString stringByReplacingOccurrencesOfString:#"’" withString:#"\'"];
contentString = [contentString stringByReplacingOccurrencesOfString:#"<p>" withString:#""];
contentString = [contentString stringByReplacingOccurrencesOfString:#"</p>" withString:#"\n"];
detailView.content = contentString;
detailView.title = [[jsonArray objectAtIndex:indexPath.row] objectForKey:#"title"];
NSString *startDate = [[jsonArray objectAtIndex:indexPath.row] objectForKey:#"StartDate"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:startDate];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
detailView.eventTime = [dateFormatter stringFromDate:date];
//Pull Image from web and serve to next page
NSDictionary *imageInfo = [[jsonArray objectAtIndex:indexPath.row] objectForKey:#"featured_image"];
NSDictionary *attachmentMeta = [imageInfo objectForKey:#"attachment_meta"];
NSDictionary *sizes = [attachmentMeta objectForKey:#"sizes"];
NSDictionary *blogFull = [sizes objectForKey:#"blog-full"];
NSString *url = [blogFull objectForKey:#"url"];
detailView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
}
}
In your completion block: [self.tableview reloadData]. Documentation.
Actually, you will want to create a weak reference to self, then use the weak reference in your completion block.

Signature did not match getting error while trying to download file from azure server from iOS

Creating request to Microsoft Azure Server
-(void)createRequest{
NSString *strAccountName = #"assetmanagerwebmapfiles";
NSString *strContainerName = #"fieldclientgdbmapfiles";
NSString *strBlob = #"gsiscout.geodatabase";
NSString *strSecurityKey =#"gvXSY7kFx/juHRXFus7Hc2DyRViCkUBvAn9NwmvMU86cnemucqTxRX8FasdfTOmPHASYHav0Dasd89H4wGRRrfjat/pw==";
dateFormatter setDateFormat:#"yyyy-MM-dd"];
NSDate *now = [NSDate date];
NSString *iso8601StringDt1 = [dateFormatter stringFromDate:now];
NSDateComponents *components= [[NSDateComponents alloc] init];
[components setDay:1];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *strDate1 = [calendar dateByAddingComponents:components toDate:[NSDate date] options:0];
NSString *iso8601StringDt2 = [dateFormatter stringFromDate:strDate1];
NSString *strSignature = [self createSignatureSharedkey:strSecurityKey];
NSString *strURL = [NSString stringWithFormat:#"https://%#.blob.core.windows.net/%#/%#?sv=2012-02-12&st=%#&se=%#&sr=b&sp=r&sig=%#",strAccountName,strContainerName,strBlob, iso8601StringDt1,iso8601StringDt2,strSignature];
NSURL *blobURL = [NSURL URLWithString:strURL];
NSMutableURLRequest *blobRequest = [NSMutableURLRequest requestWithURL:blobURL];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:blobRequest delegate:self];
if (theConnection) {
receivedData = [NSMutableData data];
} else {
// We should inform the user that the connection failed.
}}
Genrating Shared Key “Used to authenticate access to the blob. The signature is an HMAC computed over a string-to-sign and key using the SHA256 algorithm, and then encoded using Base64 encoding. ”As per suggested by MS Azure Documents.
-(NSString*)createSignatureSharedkey:(NSString *)key{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *now = [NSDate date];
[dateFormatter setDateFormat:#"yyyy-MM-dd"];
NSString *iso8601StringDt1 = [dateFormatter stringFromDate:now];
NSLog(#"Start time:%#",iso8601StringDt1);
NSDateComponents *components= [[NSDateComponents alloc] init];
[components setDay:1];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *strDate1 = [calendar dateByAddingComponents:components toDate:[NSDate date] options:0];
NSString *iso8601StringDt2 = [dateFormatter stringFromDate:strDate1];
NSLog(#"Expiry time:%#",iso8601StringDt2);
NSString *messageToSign = [NSString stringWithFormat:#"r\n%#\n%#\nassetmanagerwebmapfiles/fieldclientgdbmapfiles/gsiscout.geodatabase\n2012-02-12",iso8601StringDt1,iso8601StringDt2];
const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [messageToSign cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSData * HMACData =[[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
NSString *base64Hash = [HMACData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSLog(#"Encrypted hash: %#", base64Hash);
return base64Hash;}
Now Here are the NSURLConnection Delegate methods
-(void)connection:(NSConnection*)conn didReceiveResponse:(NSURLResponse *)response {
if (receivedData == NULL) {
receivedData = [[NSMutableData alloc] init];
}
[receivedData setLength:0];
NSLog(#"didReceiveResponse: responseData length:(%lu)", (unsigned long)receivedData.length);}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(#"---------- Finished Loading-------------");
NSString *jsonString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(#"%#",jsonString);}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(#"Failed: %#",[error description]);}
Error Which I am getting from the server is
<Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:0d684b92-0001-0076-268e-435181000000
Time:2014-12-10T08:29:12.5587707Z</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was r
2014-12-10
2014-12-11
/assetmanagerwebmapfiles/fieldclientgdbmapfiles/gsiscout.geodatabase
2012-02-12</AuthenticationErrorDetail></Error>
Any help would be appreciated. Thanks

Iphone: How to split NSData video file into chunks and upload the chunks one by one to the server?

I have been trying to split the video file into chunks and send the chunks to the server one by one. But i am not sure if the logic or the code i have written is right! If you could please help me with this.
-(void)multipart:(NSData *)file ;
{
NSDate *currentTime = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"hh-mm"];
NSString *resultString = [dateFormatter stringFromDate: currentTime];
myDid = [[NSString alloc]initWithString:[[UIDevice currentDevice]uniqueIdentifier]];
upload_Id = [NSString stringWithFormat:#"%#%#", myDid, resultString];
NSLog(#"%#", upload_Id);
NSUInteger length = [file length];
NSUInteger chunkSize = 100 * 1024;
NSUInteger offset = 0;
do {
NSUInteger thisChunkSize = length - offset > chunkSize ? chunkSize : length - offset;
NSData *chunk = [NSData dataWithBytesNoCopy:(char *)[file bytes] + offset length:thisChunkSize freeWhenDone:YES];
//NSLog(#"%#", chunk);
//NSLog(#"%#", thisChunkSize);
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:#"mov", #"uploadExtn", upload_Id, #"uploadId",offset , #"uploadedByte", nil];
NSDictionary *mainDictionary = [[NSDictionary alloc]initWithObjectsAndKeys:#"createContent",#"type",dictionary,#"data", nil];
NSString *mainString = [mainDictionary JSONRepresentation];
offset += thisChunkSize;
NSLog(#"%d", offset);
//[chunk writeToFile:[self.recordedChunkFile path] atomically:YES];
//NSLog(#"%#", [self.recordedChunkFile path]);
//NSString* path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES) lastObject];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#://%#/%#",[[NSUserDefaults standardUserDefaults] objectForKey:DEFAULTS_SET_HTTP_SWITCH],DB_SAVED_SERVER,API_MULTIPART_UPLOAD]];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
//[request setFile:[self.recordedChunkFile path] forKey:#"data1"];
// Upload an NSData instance
[request setData:chunk withFileName:upload_Id andContentType:#"video/mov" forKey:#"data1"];
[request setPostValue:mainString forKey:#"jsonData"];
} while (offset < length);
}
Thank you

Resources