Use of undeclared indentifier 'GMSMarker' - google-maps-sdk-ios

I added #import to my .h
Why does this XCODE not recognize 'GMSMarker' but does recognize GSMMarkerOptions?
this does not work (from documentation):
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(0, 0);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = #"Hello World";
marker.map = mapView_;
this works fine:
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.title = #"gsmmarkeroptions does exist";

It sounds like you have version 1.1.2 of the SDK, but you need to get the latest version 1.2.
In 1.2 GMSMarkerOptions was removed, and now you use GMSMarker directly.

Related

Retrieve contents from HTML which is a NSString

This is my NSString :
NSString timeString = #"<h5 style="direction:ltr"><span data-version-created-date="20180326T120530.000+0000" class="releasedDate">26-Mar-2018 12:05:30</span></h5>";
I want to retrieve only "26-Mar-2018 12:05:30" which is in the span tag.
How do i do that in Objective C?
Please note : The given HTML is in NSString format.
Try this
- (NSString *)stringByStrippingHTML : (NSString*) s {
NSRange r;
while ((r = [s rangeOfString:#"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
s = [s stringByReplacingCharactersInRange:r withString:#""];
return s;
}
This will work by stripping out bracketed (<>) expressions. Slashes have been added () to timeString to make it proper NSString*. The stripping is repeated four times, bt should probably be looped with condition.
NSString * timeString = #"<h5 style=\"direction:ltr\"><span data-version-created-date=\"20180326T120530.000+0000\" class=\"releasedDate\">26-Mar-2018 12:05:30</span></h5>";
NSRange openRange = [timeString rangeOfString:#"<"];
NSRange closeRange = [timeString rangeOfString:#">"];
NSRange enclosedRange = NSMakeRange(openRange.location, closeRange.location-openRange.location+1);
timeString = [timeString stringByReplacingCharactersInRange:enclosedRange withString:#""];
openRange = [timeString rangeOfString:#"<"];
closeRange = [timeString rangeOfString:#">"];
enclosedRange = NSMakeRange(openRange.location, closeRange.location-openRange.location+1);
timeString = [timeString stringByReplacingCharactersInRange:enclosedRange withString:#""];
openRange = [timeString rangeOfString:#"<"];
closeRange = [timeString rangeOfString:#">"];
enclosedRange = NSMakeRange(openRange.location, closeRange.location-openRange.location+1);
timeString = [timeString stringByReplacingCharactersInRange:enclosedRange withString:#""];
openRange = [timeString rangeOfString:#"<"];
closeRange = [timeString rangeOfString:#">"];
enclosedRange = NSMakeRange(openRange.location, closeRange.location-openRange.location+1);
timeString = [timeString stringByReplacingCharactersInRange:enclosedRange withString:#""];
NSLog(#"timeString = %#", timeString);
This worked with me
NSString *timeString = #"<h5 style=\"direction:ltr\"><span data-version-created-date=\"20180326T120530.000+0000\" class=\"releasedDate\">26-Mar-2018 12:05:30</span></h5>";
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:#">\\d.+\\d<"
options:NSRegularExpressionCaseInsensitive
error:NULL];
[regex enumerateMatchesInString:timeString options:0 range:NSMakeRange(0, [timeString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
// your code to handle matches here
NSString *subString = [timeString substringWithRange:match.range];
NSLog(#"%#",[subString substringWithRange:NSMakeRange(1, subString.length - 2)]);
}];
If you want to make sure you get the date between the span tags, it would be best to be more explicit than either stripping out all the HTML tags and assuming the only thing left is the date, or assuming there is only one span tag in the whole HTML text. It may work for now, but that will likely break in the future if the HTML ever changes.
NSString * timeString = #"<h5 style=\"direction:ltr\"><span data-version-created-date=\"20180326T120530.000+0000\" class=\"releasedDate\">26-Mar-2018 12:05:30</span><span class=\"someOtherClass\">garbageData</span></h5>";
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:#"<span.*class=\"releasedDate\"[^>]*>(.*)</span.*>"
options:NSRegularExpressionCaseInsensitive
error:nil];
NSTextCheckingResult *textCheckingResult = [regex firstMatchInString:timeString options:0 range:NSMakeRange(0, timeString.length)];
NSString *releaseDateString = [timeString substringWithRange:[textCheckingResult rangeAtIndex:1]];
if( ! [releaseDateString isEqualToString:#""] )
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd-MMM-yyyy' 'HH:mm:ss"];
NSDate *releaseDate = [dateFormatter dateFromString:releaseDateString];
NSLog( #"%# - %#", releaseDateString, releaseDate );
}
Note that this works even if there are other spans in the HTML text. It specifically pulls out the one with a class "releasedDate".

How to encode odd HTML characters with Xcode?

I need to save a HTML page in my app, and when characters like "€" are found, the saved file displays them wrong.
I tried several encodings but none solves this, is there any solution?
I have also tried to replace the characters for the HTML name, but it still doesn't work.
Here's my code:
NSString *HTML = [web stringByEvaluatingJavaScriptFromString:#"document.getElementsByTagName('html')[0].innerHTML;"];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:#"%#/%#", [path objectAtIndex:0],#"code.html"];
int enc_arr[] = {
NSISOLatin1StringEncoding, // ESP
NSUTF8StringEncoding, // UTF-8
NSShiftJISStringEncoding, // Shift_JIS
NSJapaneseEUCStringEncoding, // EUC-JP
NSISO2022JPStringEncoding, // JIS
NSASCIIStringEncoding // ASCII
};
NSData *urlData= nil;
for (int i=0; i<6; i++) {
urlData = [HTML dataUsingEncoding:enc_arr[i]];
if (urlData!=nil) {
break;
}
}
[urlData writeToFile:filePath atomically:YES];
See these methods of NSString:
- (NSStringEncoding)smallestEncoding
- (NSStringEncoding)fastestEncoding
or just use method below with flag set to YES :
- (NSData *)dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)flag
but with this one you can loose some characters.
Ok I finally did it, it's not the best way but the only one that worked for me and without using external libraries:
-(NSString*)escapeHTML:(NSString*)code{
NSMutableArray *maExceptions = [[NSMutableArray alloc] initWithObjects: #"Œ", #"œ", #"Š", #"š", #"Ÿ", #"ƒ", #"‘", #"’", #"‚", #"“", #"”", #"„", #"†", #"‡", #"•", #"…", #"‰", #"€", #"™", nil];
for (int i=0; i<[maExceptions count]; i++) {
code = [code stringByReplacingOccurrencesOfString:[maExceptions objectAtIndex:i] withString:[NSString stringWithFormat:#"&#x%x;",[[maExceptions objectAtIndex:i] characterAtIndex:0]]];
}
return code;
}

Three20 Navigation: View don't show

I rework my app to use Three20 and I wanna use Three20 navigation now.
Here is my code, that works perfectly before:
ENSListViewController *vc = [ENSListViewController alloc];
NSArray *ensArray;
NSDictionary *dic;
NSInteger folder_id;
NSString* folder_type;
NSString* barTitle;
NSString* folderName;
if (indexPath.section == 0)
{
ensArray = [ensFolderList objectForKey:#"an"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"an";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
else
{
ensArray = [ensFolderList objectForKey:#"von"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"von";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
vc.folder_id = folder_id;
vc.folder_type = folder_type;
vc.barTitle = barTitle;
vc.folderName = folderName;
[vc initWithNibName:#"ENSListViewController" bundle:nil];
[self.view addSubview:vc.view];
It works perfectly.
It allocs a ViewController, sets a lot of data in the ViewController (Properties) and then show the view.
Here is my code now:
NSArray *ensArray;
NSDictionary *dic;
NSInteger folder_id;
NSString* folder_type;
NSString* barTitle;
NSString* folderName;
if (indexPath.section == 0)
{
ensArray = [ensFolderList objectForKey:#"an"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"an";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
else
{
ensArray = [ensFolderList objectForKey:#"von"];
dic = [ensArray objectAtIndex:indexPath.row];
folder_type = #"von";
barTitle = [NSString stringWithFormat:#"%#", [dic objectForKey:#"name"]];
folder_id = [[dic objectForKey:#"ordner_id"] intValue];
folderName = [dic objectForKey:#"name"];
}
/*
vc.folder_id = folder_id;
vc.folder_type = folder_type;
vc.barTitle = barTitle;
vc.folderName = folderName;
[vc initWithNibName:#"ENSListViewController" bundle:nil];
//[self.view addSubview:vc.view];
*/
NSString *url = [NSString stringWithFormat:#"tt://ensList/%#/%#/%d/%#/%#/%#", #"ENSListViewController", nil, folder_id, folder_type, barTitle, folderName];
TTURLAction *action = [TTURLAction actionWithURLPath:url];
[[TTNavigator navigator] openURLAction:action];
Here is my Navigator:
navigator = [TTNavigator navigator]; // create the navigator
navigator.persistenceMode = TTNavigatorPersistenceModeAll; // and he will save the data :)
TTURLMap* map = navigator.URLMap;
[map from: #"tt://ens"
toSharedViewController: [ENSOverviewViewController class]];
[map from: #"tt://ensList/(initWithNibName:)/(bundle:)/(folderId:)/(folderType:)/(barTitle:)/(folderName:)" toViewController:[ENSListViewController class]
transition:3];
And here is my new Constructor method:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self LoadENSList];
}
return self;
}
- (void) initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil folderId:(NSInteger)folder_id2 folderType:(NSString*)folder_type2 barTitle:(NSString*)barTitle2 folderName:(NSString*)folderName2
{
self.folder_id = folder_id2;
self.folder_type = folder_type2;
self.barTitle = barTitle2;
self.folderName = folderName2;
[self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
}
So, if you read it up to here: big thanks!
Now my problem is: The view doesn't open. Nothing happens.
I think there is a mistake in my self made constructor, the order of calling my constructor or something like this. Im on it since 2 hours but can't find the error.
I know Three20 is much undocumented and I am not expacting a fast answer, but if anyone have an idea: please comment or answer.
Found the solution:
1) I forget the return-value in my constructur.
After adding this (changing (void) to (id) and add "return self") it goes on...
2) After he changes in 1) the system crashes because initWithNibName throws an NSInvalidArgument error.
After changing this to init, it works perfectly

CLLocation distanceFromLocation always return 0

I'm having a problem when using the distanceFromLocation method, where it always returns zero.
Here's my code snippet:
NSArray *arrATMItem = [arrATMs objectAtIndex:indexPath.row];
cell.textLabel.text = [arrATMItem objectAtIndex:0];
float lat = [[arrATMItem objectAtIndex:1] floatValue];
float lon = [[arrATMItem objectAtIndex:2] floatValue];
CLLocation *branchLoc = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
CLLocationDistance dist = [currentLocation distanceFromLocation:branchLoc];
NSLog(#"distance = %d",dist);
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:#"%d m", dist];
I have also checked that the branchLoc and currentLoc instances have the right values.
Here's an example value of branchLoc:
lat: -6.17503957 long: 106.79891717
And a value for currentLoc is:
lat: -6.17603957 long: 106.79891717
The branchLoc values are retrieved from a plist file, and the currentLoc is obtained from the CLLocation class on the CLLocation locationUpdate method defined in my delegate file.
I tried using %f , and it also returns something like 0.00000.
Any idea what I'm doing wrong?
Thanks
Try using double (or CLLocationDegrees) for lat and lon.

MFMailComposeViewController csv attachment not being attached, but showing inline instead

I am having a problem with sending csv attachments via MFMailComposeViewController.
Sometimes they come through just fine, but for other users they don't come through as attachments, but rather as text inline in the email (with <br/> instead of line returns.) It's very strange. Anybody know what I'm doing wrong?
Here is a snippet of my code:
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
NSString *csv = #"foo,bar,blah,hello";
NSData *csvData = [csv dataUsingEncoding:NSUTF8StringEncoding];
[mailComposeViewController addAttachmentData:csvData mimeType:#"text/csv" fileName:#"testing.csv"];
[mailComposeViewController setSubject:#"testing sending csv attachment"];
[mailComposeViewController setMessageBody:#"csv file should be attached" isHTML:NO];
[self presentModalViewController:mailComposeViewController animated:YES];
-(IBAction)btnPressed:(id)sender {
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDir = [arrayPaths objectAtIndex:0];
NSString *Path = [docDir stringByAppendingString:#"/CSVFile.csv"];
NSData *csvData = [NSData dataWithContentsOfFile:Path];
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"For csv file..."];
[controller setMessageBody:#"...csv file is hear.." isHTML:NO];
[controller addAttachmentData:csvData mimeType:#"text/csv" fileName:#"CSVFile.csv"];
[self presentModalViewController:controller animated:YES];
[controller release];
}
Hi I put sample code for Creating CSV file and attach it with mail but make sure you have to add MessageUI.Framework and import its related header "MessageUI/MessageUI.h"
"MessageUI/MFMailComposeViewController.h" and deligate "MFMailComposeViewControllerDelegate"...I hope this wl useful for others
- (void)viewDidLoad {
arrCsv=[[NSArray alloc]initWithObjects:#"Hello",#"Hi",#"traun",#"fine",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:#"%#/try.csv", documentsDirectory];
[[arrCsv componentsJoinedByString:#","] writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
-(ibAction)btnMail {
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDir = [arrayPaths objectAtIndex:0];
NSString *Path = [docDir stringByAppendingString:#"/CSVFile.csv"];
NSData *csvData = [NSData dataWithContentsOfFile:Path];
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"For csv file..."];
[controller setMessageBody:#"...csv file is hear.." isHTML:NO];
[controller addAttachmentData:csvData mimeType:#"text/csv" fileName:#"CSVFile.csv"];
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{ message.hidden = NO;
switch (result)
{
case MFMailComposeResultCancelled:
message.text = #"Result: canceled";
break;
case MFMailComposeResultSaved:
message.text = #"Result: saved";
break;
case MFMailComposeResultSent:
message.text = #"Result: sent";
break;
case MFMailComposeResultFailed:
message.text = #"Result: failed";
break;
default:
message.text = #"Result: not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
set the mime type as "application/octet-stream" and that should do the trick to remove inline attachments (I still named the extension of my file i.e. pdf)
I believe the second parameter to setMessageBody:isHTML: must be YES for attachments to not show up inline.
Even if you set isHTML param to YES, your message body can be sent as plain/text if the message body can be represented as such. And attachments in plain/text messages are not always recognized correctly by some email clients (Outlook).
In my case adding a link in the message body helped. Formatting text as bold with HTML tags works too. Tricky!
Tested on iPod 1G 3.1.3.
This may not be the case here, but one thing to watch out for is that:
[NSString dataUsingEncoding:]
returns a valid but empty NSData object if the conversion to the specified encoding is not possible. Better to use the full version:
[NSString dataUsingEncoding: s allowLossyConversion: YES]
Or check the length of the returned data. It appears that zero-length data attachments are trimmed somewhere in the mail process.