Send user location coordinates to SMS.app as an googleMaps-link - iphone

I wanna send my location coordinates as a Google Maps link (http://maps.google.com/?saddr=%1.6f,%1.6f) as an SMS but i just can't get it to work... How should I do so that the GoogleMaps-link varies to my location??
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.body = #"This is my location http://maps.google.com/?saddr=%1.6f,%1.6f";
NSString *googleMaps = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f", location.latitude, location.longitude];
controller.recipients = [NSArray arrayWithObjects:nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
Any ideas? Would really appreciate an answer!!!!
Thanks you and happy holidays!

shouldn't you have:
controller.body = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f", location.latitude, location.longitude];
you're hard coding the body and then creating an unrelated string which is probably properly formatted and never doing anything with it.

you need to do location.coordinate.latitude, location.coordinate.longitude assuming location is a cllocation object.

Related

Search nearby in iOS Maps

I am trying to build a simple application using MapKit that will automatically search for a specific place when the app launches and drop pin(s) on the map at the locations(s). I am seeing all sorts of ways to load locations (lat/lon, etc), but nothing that lets me search for a specific business name, restaurant name, etc.
I am expecting to work with Apple Maps. However, if Google Maps would be a better solve than so be it.
Any help would be appreciated. Thanks
iOS >= 6.1 provides MKLocalSearch, MKLocalSearchRequest to search for natural language points of interest. Sample
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.region = regionToSearchIn;
request.naturalLanguageQuery = #"restaurants"; // or business name
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
// do something with the results / error
}];
i know its late but hope this helps!
[super viewDidLoad];
[self.searchDisplayController setDelegate:self];
[self.ibSearchBar setDelegate:self];
self.ibMapView.delegate=self;
// Zoom the map to current location.
[self.ibMapView setShowsUserLocation:YES];
[self.ibMapView setUserInteractionEnabled:YES];
[self.ibMapView setUserTrackingMode:MKUserTrackingModeFollow];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
[locationManager startUpdatingLocation];
[self.ibMapView setRegion:MKCoordinateRegionMake(locationManager.location.coordinate, MKCoordinateSpanMake(0.2, 0.2))];
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.region = self.ibMapView.region;
request.naturalLanguageQuery = #"restaurant";
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
results = response;
if (response.mapItems.count == 0)
NSLog(#"No Matches");
else
for (MKMapItem *item in response.mapItems)
{
NSLog(#"name = %#", item.name);
NSLog(#"Phone = %#", item.phoneNumber);
[_matchingItems addObject:item];
MKPointAnnotation *annotation =
[[MKPointAnnotation alloc]init];
annotation.coordinate = item.placemark.coordinate;
annotation.title = item.name;
[self.ibMapView addAnnotation:annotation];
}
}];
}
Make the following steps to display nearest places.
Using google API find the Nearest Places Google Places API
The google API provide LAt and Long and address Informations.
Then Store the LAt and Long Values to Array then USing this lat and long values you can display Annotations in Apple map (iOS 6+) and Google Map (iOS 5).

How to change message details (email body) in MFMailComposeViewController?

I seem to have fallen fowl of something that seems like it should be very simple!
How do I now populate an email's body with the strings a user has entered into NSUserDefaults?
Basically there is a button else ware that enters a sting such as 'YES' into NSUserDetaults. How do I make the email body those stored strings.
This is the code I currently have:
- (IBAction)buttonPressed:(id)sender {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"SYS"];
[controller setMessageBody:#"How do I make this the content of NSUSERDEFAULTS?" isHTML:NO];
controller.navigationBar.barStyle = UIBarStyleBlack;
[self presentViewController:controller animated:YES completion:nil];
Any help would be greatly appreciated!
Thanks!
Using your code the strings appear as : Yes, No, Maybe, No way,
How can I alter the format to make them appear
Yes,
No,
Maybe,
No way.
Thanks again for your time!
What you want is a line break character, which can be achieved with \n (newline).
NSArray *storedStrings = [[NSUserDefaults standardUserDefaults] objectForKey:#"yourStoredKey"];
NSMutableString *messageBody = [NSMutableString string];
for (NSString *aString in storedStrings) {
[messageBody appendFormat:#"%#,\n\n", aString];
}
[messageBody deleteCharactersInRange:NSMakeRange(messageBody.length-3, 3)];
[controller setMessageBody:messageBody isHTML:NO];
That line I added right after the for loop will remove the last three characters from the string, i.e. the two newline characters and the comma.
Try this method
- (IBAction)buttonPressed:(id)sender {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"SYS"];
[controller setMessageBody:[[nsstring stringwithformat#"%#",[[NSUserDefaults standardUserDefaults] objectForKey:#"yourStoredKey"]] isHTML:NO];
controller.navigationBar.barStyle = UIBarStyleBlack;
[self presentViewController:controller animated:YES completion:nil];

iOS UIActivity View Controller: Add To Reading List Button?

Is there a service to be able to add a URL to the iOS Safari's Reading List from in a app.
I would have a url to add and a UIWebView,but I have researched and I can't find anything.
Here is my working UIActivityViewController.
-(IBAction)actionButton:(id)sender;{
NSLog(#"shareButton pressed");
NSURL *URL = [NSURL URLWithString:self.feedItem[#"url"]];//this is your text string
NSArray *activityItems = #[URL];
ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];
TUSafariActivity *TUSafari = [[TUSafariActivity alloc] init];
MLCruxActivity *cruxActivity = [[MLCruxActivity alloc] init];
NSArray *applicationActivities = [NSArray arrayWithObjects:TUSafari,chromeActivity,cruxActivity, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities: applicationActivities];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
UPDATE: iOS 7 added an API to accomplish this:
#import <SafariServices/SafariServices.h>
SSReadingList * readList = [SSReadingList defaultReadingList];
NSError * error = [NSError new];
BOOL status =[readList addReadingListItemWithURL:[NSURL URLWithString:urlToAdd] title:titleToAdd previewText:previewText error:&error];
if(status)
{
NSLog(#"Added URL");
}
else NSLog(#"Error");
Currently (iOS SDK 6.1) there is no way to add a item to the Reading List from a third party app.
There are some alternatives like Readability you could use.

Simulating sent SMS on iPhone

Since debugging is extremely slow with Xcode 4.3 on iOS 5.1 when starting/installing the app on the device I use the simulator which starts much faster. (see my question regarding this issue here https://stackoverflow.com/questions/11541288/xcode-4-3-with-ios5-1-pauses-about-10secs-when-debug-starts-simulator-starts-i)
So all I need to do is something like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MessageComposeResult result = MessageComposeResultSent; <-----------
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
Here the problem is now that when executing on iOS-Simulator the MFMessageComposeViewController can't be instantiated and always yields nil.
Is there a way to create another object MyOwnMFMessageComposeViewController on iOS simulator which is compatible to MFMessageComposeViewController and can be passed in the same method like MFMessageComposeViewController?
Something like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MyOwnMFMessageComposeViewController *mypicker = [[MFMessageComposeViewController alloc] init];
mypicker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
mypicker.recipients =[NSArray arrayWithObject: s];
mypicker.body =smsTxt;
MessageComposeResult result = MessageComposeResultSent;
picker = (MFMessageComposeViewController) mypicker;
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
What you are looking for is called a 'mock object' and is often used in test driven development. Basically what you do is create a subclass of MFMessageComposeViewController. This subclass works exactly the same as mfmessagecomposeviewcontroller except you also create instance variables to show that something has happened.
So for example when your delegate calls messageComposeViewController:didFinishWithResult. The mock object would likely store the result and a flag that that method had been fired. Note that this won't actually send anything, but simply tells you that the delegate fired and on a real object will work.

iPhone SMS Url Scheme with Body Content?

I am looking to pre-fill the SMS body with content given "smsto:555-555-5555:Hello World"
I have done my research and everybody says it cannot be done but I have a QR reader on my phone right now that can take "sms:555-555-5555:Hello world" and pre-fills the content with the correct phone number scanned.
So my question is. How do i do this? it is pretty clear that the URL scheme provided doesn't handle the body. What other methods are out there to pre-fill the body? it can clearly be done with the QuickMark Reader.
You can use the modalViewController for SMS to fill the body of a text.
add the MessageUI framework to your project.
set you viewController as the MFMessageComposeDelegate
Create the modal view and present it:
-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = delegate;
[delegate presentModalViewController:controller animated:YES];
}
}
You can't launch the Messages app with a predefined message according to Apple Documentation.
What you can do is implement the handling yourself and parse the URL like the following:
NSURL *url = /* the url you get from the web (in webview delegate) or after QR Code scan */;
if ([url.scheme isEqualToString:#"sms"]) // is it a sms ?
{
if([MFMessageComposeViewController canSendText]) // can I send text message ?
{
NSArray *parts = [url.absoluteString componentsSeparatedByString:#":"];
NSString *messageText = parts.count == 3 ? [parts objectAtIndex:2] : #"";
NSString *telNumber = parts.count >= 2 ? [parts objectAtIndex:1] : #"";
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
}
And voilĂ  !