Best way to combine string and placemark data for NSUrl? - nsstring

I'm trying to get the temp and weather data for my app based on the latitude and longitude location...
How can I get this to work?
NSURL *jsonurl = [NSURL URLWithString:#"http://www.myweather2.com/developer/forecast.ashx?uac=(API-KEY)&output=json&query=",placemark.location,#"&temp_unit=f"];

NSString *jsonStr = [NSString stringWithFormat:#"http://www.myweather2.com/developer/forecast.ashx?uac=(API-KEY)&output=json&query=%#&temp_unit=f", placemark.location];
NSURL *jsonurl = [NSURL URLWithString:jsonStr];
This assumes that the value for placemark.location is an NSString that only contains valid URL characters.

Related

route drawing using google api not working in objc

i was using http://maps.google.com/maps?output=dir&saddr=%#&daddr=%# api for the step based route plotting . Till the last week i got the response in correct manner . But now the response is only null . Can anyone faced the same issue . Apple map is not plotting correctly in india . when we plot google map/direction api the step is not proper in MKMapkit. Is there any other way to have an accurate map in ObjectiveC
my code is below
NSString* saddr = [NSString stringWithFormat:#"%f,%f", f.latitude, f.longitude];
NSString* daddr = [NSString stringWithFormat:#"%f,%f", t.latitude, t.longitude];
NSString* apiUrlStr = [NSString stringWithFormat:#"http://maps.google.com/maps?output=dir&saddr=%#&daddr=%#", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
NSLog(#"api url: %#", apiUrl);
NSError* error = nil;
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl encoding:NSASCIIStringEncoding error:&error];
NSLog(#"%#",apiResponse);

NSString with HTML code to NSData

Thanks in advance!
I'm wondering if it's possible to convert HTML code stored in a NSString to a NSData to parse later.
I'm reading from a BBDD the HTML code and saving it into a NSString.
NSString *htmlString =#"<html><body><p>introduccion</p><p>introducción</p></body></html>";
I want to use:
NSData *nsData = [[NSData alloc] initWithContentsOfURL:url];
But instead of initWithContentsOfURL i have to use the htmlString because I have the code stored in a BBDD and I am accessing it and storing the code to a NSString
Thanks!
Why dont you use standard methods to convert NSString to NSData like this:
NSData* data = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
I have some html formatted text in my "subject.details", I add some more html formatting on the front and back. Giving me a "detailsStringForDisplay" NSString.
I convert this string to an NSData.
Set up a dictionary, which only contains one element to say that the document type is HTML.
Then finally set an attributedText using the data and the dictionary.
NSString *fontDetailsHTML = #"<div style=\"font-size:17px; text-family:Georgia; \">";
NSString *detailsString = subject.details;
NSString *endFontDetailsHTML = #"</div>";
NSString *detailsStringForDisplay = [NSString stringWithFormat:#"%#%#%#",fontDetailsHTML,detailsString,endFontDetailsHTML];
NSData *labelTextData = [detailsStringForDisplay dataUsingEncoding:NSUnicodeStringEncoding allowLossyConversion:true];
NSDictionary *attributesForText = [[NSDictionary alloc]initWithObjectsAndKeys:NSHTMLTextDocumentType,NSDocumentTypeDocumentAttribute , nil];
self.detailDescriptionLabel.attributedText = [[NSAttributedString alloc]initWithData:labelTextData options:attributesForText documentAttributes:nil error:nil];

Error adding NSString variable into plist file

I've a problem I'm struggling with for a lot of time...please help.
I'm using the following line of code to add record to a plist file:
[data_appo setObject:#"string value" forKey:[NSString stringWithFormat:#"%i",(i-1)]];
and it works ok. Now,if I try to read the string from the file than adding it (I need to duplicate the value with a different key) as follows
NSString *string_appo=[data_appo objectForKey:[NSString stringWithFormat:#"%i",j]];
[data_appo setObject:string_appo forKey:[NSString stringWithFormat:#"%i",(i-1)]];
then I gest ERROR_EXEC and the app crashes...
Any idea???
Any help will be appreciated
Thanks in advance!
Have you saved the plist file after making the addition. I do this a lot and I do it like this
//find the plist file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"Notes.plist"];
//set the value for the key
[notesData setValue:textView.text forKey:[NSString stringWithFormat:#"General notes %d",selectedIndex]];
//save the plist file
[notesData writeToFile: path atomically:YES];
//relese and reload it
[notesData release];
notesData = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
I hope this helps!

NSTimeInterval from text input

I got a question for anyone with a spare moment and an answer...
I need to change an NSString value to input into the AVAudioPlayer start offset
eg. player.currentTime = 0; I want to change the '0' to a readable value or an NSString to a numeral value.....
NSString has a integerValue function. You can also create an NSString using it's format class function and pass it a format string like this: "%d" and then your player.currentTime.
int timeInput = [[textField text] integerValue];
label.text = [NSString stringWithFormat:#"%d", timeInput];

CoreData - NSPredicate formated with time range (NSTimeInterval)

I'm trying to find out how to go through my CoreData information and find objects that have a createdAt (part of my object as an NSDate) that is within a NSTimeInterval. How do I set this up?
I've looked on the documentation at:
http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html
But I'm not finding anything there.
Do I need to create two time stamps and use SQL's BETWEEN?
Any help would be wonderful.
First of all, it doesn't make sense to check if an NSDate is within an NSTimeInterval, because NSTimeInterval just specifies a length of time, not its location. Instead, you want to use two separate NSDates specifying the beginning and end of your intervals.
Here's what it would look like (beginningTime and endTime are NSDates).
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:#"YourEntityName" inManagedObjectContext:yourContext];
NSPredicate *beginningPredicate = [NSPredicate predicateWithFormat:#"createdAt >= %#", beginningTime];
NSPredicate *endPredicate = [NSPredicate predicateWithFormat:#"createdAt <= %#", endTime];
request.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:beginningPredicate, endPredicate, nil]];
NSArray *results = [yourContext executeFetchRequest:request error:NULL];

Resources