It is really frustrating me. I used the doc provided by Navigon itself. Unfortunately it doesn't work as expected. Navigon launches, but stops at the main menu.
All I do is this:
NSString *myTestStr = [NSString stringWithFormat:#"navigon://App|Another place|FRA|75008|PARIS|rue de Turin|17|2.324621|48.881273"];
NSString *navigonStrEsc = [myTestStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"navigonStr: %#", navigonStrEsc);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:navigonStrEsc]];
Any ideas what is wrong with my way?
thanks a lot!
Finally I figured out the right solution. The secret ingredients that the Navigon app interchanged the latitude and longitude values.
Use this custom url scheme to pass the navigation destination coordinates (the passed coordinates have to be on the loaded map):
navigon://coordinate/YourAppName/longitude/latitude
For example: navigon://coordinate/NaviCard/19.084443/47.573305
hum it should work. Here's my code:
The only diff is that my scheme changes if FRA is installed , then navigonFRA is prefered.
NSString* scheme = #"navigonFRA";
if ((![NavigonApplication isFRInstalled]) && [NavigonApplication isWorldInstalled])
scheme = #"navigon";
NSString* urlAsString = nil;
urlAsString = [NSString stringWithFormat:#"%#://%#|%#|%#|%#|%#|%#|%#|%f|%f",
scheme,
#"myApp", // Field1/AppName:Application or Company Name (e.g. AroundMe)
thePOI.name, // Field2/NameOfPOI: Name of POI (e.g. Navigon AG Würzburg)
#"FRA", // Field3/Country: ISO 3166-1 alpha-3 code for country (http://unstats.un.org/unsd/methods/m49/m49alpha.htm) (e.g. DEU)
#"", // Field4/ZipCode: Postalcode, ZIP code of the POIs city (e.g. 97080)
thePOI.location.city, // Field5/City: Name of POIs city (e.g. Würzburg)
thePOI.location.streetAddress, // Field6/Street:POIs street name (e.g. Berliner Platz)
#"", // Field7/HouseNumber: POIs street/house number (e.g. 11)
thePOI.location.longitude, // Field8/Longitude: Longitude in WGS84 (e.g. 9.870)
thePOI.location.latitude]; // Field9/Latitude: Latitude in WGS84 (e.g. 49.938)
urlAsString = [urlAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"Starting Navigon app with %#", urlAsString);
NSURL*url = [[NSURL alloc] initWithString:urlAsString];
[[UIApplication sharedApplication ]openURL:url];
[url release];
And this code is working. Did you check that your navigon version is >= v1.5 ?
I found the problem, the first field (AppName) is pretty important.
The following html link now works :
Some nice place
For informations : I called the navigon support yesterday, the woman who answered was helpless and terribly aggressive, I'm thinking about using TomTom now :)
Related
Preamble: I'm working with some code I didn't write and I have next to no knowledge of iOS.
The app has a webview which handles most of the app; internal links are loaded in the webview and links to other sites are opened in Safari which is expected. However, embedding a google maps also causes safari to open. I found the relevant controller code, I think, and it looks like this:
// a bit higher up
static NSString *const siteURL = #"http://my.example.com"
if (![request.URL.absoluteString hasPrefix:siteUrl])
{
if ([[UIApplication sharedApplication] canOpenURL:request.URL])
{
[[UIApplication sharedApplication] openURL:request.URL];
}
return NO;
}
Now because 'maps.google.com' doesn't start with 'my.example.com' it farms out to safari - and that makes sense to me. However, I tried modifying this:
static NSString *const googleMaps = #"http://maps.google.com"
if (! ([request.URL.absoluteString hasPrefix:siteUrl] || [request.URL.absoluteString hasPrefix:googleMaps]))
{
if ([[UIApplication sharedApplication] canOpenURL:request.URL])
{
[[UIApplication sharedApplication] openURL:request.URL];
}
return NO;
}
This also works. But I need to add some more URLs. Is my only choice to keep adding 'or' and string constants? Or is there a way to make an array and say "if it matches any of these"? Sorry if this question seems simplistic.
In PHP I'd just do something like in_array('string', $array) as my condition, I guess I'm looking for how to do this in iOS
One solution would be to maintain a NSSet of objects, being all the strings that you want to be handled in your internal webview.
NSSet *internalURLSet = [NSSet setWithObjects:#"http://my.example.com", #"http://maps.google.com", nil];
Use a mutable set if you will be adding to the set over time but you will likely know which URLs you want to handle internally as soon as your app starts and this will not change. If you are adding sets as the app runs then add them to the mutable set as they become known.
When you check a URL, use [internalURLSet containsObject:urlToTest] and it will match any of the strings you have added to the set.
Checking against the set is very efficient. Adding objects to the set is less so, but you will very likely add URLs to the set only once while you check many times.
(Doing indexOfObject: against a NSArray is very inefficient...)
You could try using a predicate. Here's a tutorial link with an example (older, but should still work):
http://arstechnica.com/apple/2009/04/cocoa-dev-the-joy-of-nspredicates-and-matching-strings/
I do a lot of .NET development too and always miss LINQ when I go back to iOS. Predicates help a little, more lines of code but handy since you can do all kinds of searches.
I see your problem. In IOS, don't have a function in_array('string',$array) to check a string is contained in array.
I have a suggestion: you create a array with all urls. And implement 'for' or 'while' loop to get value of array check it. If it's same, you call function OpenUrl.
You could do this by creating an NSArray of your URLS and then using the indexOfObjectPassingTest: method to test your URL against each one in the array. It would go something like this:
NSArray *testURLs = #[ #"http://maps.google.com", #"http://www.example.com" ];
NSString *urlString = request.URL.absoluteString;
BOOL urlMatchedTest = NO;
for ( NSString *testURL in testURLs ) {
if [urlString hasPrefix:testURL] ) {
urlMatchedTest = YES;
}
}
if ( urlMatchedTest ){
// the url contains one of the test URLS
} else {
// it didn't match any of the test URLs
}
I am having one issue related extracting of string in iOS. I am getting NSURL value from WebView http://m.youtube.com/index?&desktop_uri=%2F, however i need to extract only http://m.youtube.com, i have tried many steps, however it didn't work, please help me regarding this issue.
Well looking at the NSURL class reference, I can see that an NSURL object has various properties that give you what you want:
http://m.youtube.com
| A | B |
A: Scheme
B: Host
So I think all you need to do is:
NSURL *url = ...;
NSString *scheme = url.scheme;
NSString *host = url.host;
NSLog(#"%#%#", scheme, host);
Job done. NEXT!
I have an URL -----> 182.72.253.75/test/surya/telugu.html
And this url contains some information in telugu language..
Now I need help in the following aspects---->
1) How to parse that html url..
2) How to display the information in that link in a UILabel in iphone simulator...(Because the information is in telugu language not in english language) ..
Thanks in Advance....
Here I have solved my problem...
Actually the URL contains...
ాష్ట్రపతి ప్రణబ్ ముఖర్జీ అధ్యక్షతన రాష్ట్రపతి భవన్లో గవర్నర్ల సదస్సు సోమవారం ప్రారంభమైంది. రెండు రోజుల పాటు జరిగే ఈ సదస్సులో 30 మంది గవర్నర్లు, లెప్ట్నెంట్ గవర్నర్లు పాల్గొన్నారు. ప్రధాని మన్మోహన్సింగ్తోపాటుగా, రక్షణ, ఆర్థిక, వ్యవసాయం, హోం, మానవ వనరుల అభివృద్ధి, పట్టణాభివృద్ధి, జలవనరులశాఖల మంత్రులతోపాటుగా, పౌరసర ఫరాలు, ఆహార, ప్రజాపంపిణీ, తాగునీరు, పారిశుద్ధ్య శాఖల స్వతంత్ర మంత్రులు హాజరయ్యారు. రాష్ట్రాల ఆర్థికాభివృద్ధితో పాటు మహిళల భద్రతపై ఈ సదస్సులో చర్చించనున్నారు.
The background source code of this This HTML page is as follows...
http://ashokios.blogspot.in/2013/02/background-sourcetemporary-post.html
But this is not in correct formate
so..,
1)Need to get the correct formate..
2)Need to convert into Dictionary.
Here we need two custom classes
XMLReader and GDataXMLDocument..
Now the solution is...
NSString *serverResponseStr=[XMLReader getResponseForService:#"http://182.72.253.75/test/surya/telugu.html" withParametersString:nil];
NSString *validXMLstring=[[NSString alloc]init];
GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithHTMLString:serverResponseStr error:nil];
if (doc)
{
validXMLstring=[[doc rootElement] XMLString];
}
NSDictionary *responseDictionary=[[NSDictionary alloc]init];
responseDictionary=[XMLReader dictionaryForXMLString:validXMLstring error:nil];
NSLog(#"%#",responseDictionary);
NSLog(#"%#",[[[[[[responseDictionary objectForKey:#"html"]objectForKey:#"body"]objectForKey:#"table"]objectForKey:#"tr"]objectForKey:#"td"]objectForKey:#"text"]);
self.myTextView.text=[[[[[[responseDictionary objectForKey:#"html"]objectForKey:#"body"]objectForKey:#"table"]objectForKey:#"tr"]objectForKey:#"td"]objectForKey:#"text"];
I have a NSString which is an address:
"210 Queen Street East Brampton"
I need to ping Google's Geocoding server with a URL constructed from this string that needs to look like this:
http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false
Clearly, I can append strings together to create a master string
called temp and then just
use this code to send the request:
NSMutableString *url = [[NSMutableString alloc] initWithString:temp];
The challenge I am facing is: How do I introduce the '+' signs between words instead of the spaces?
Can anyone suggest if there are built in functions in Objective C that can do this or what's the simplest way to robustly implement this?
Thanks.
I was hoping to find some method that would let you replace characters, but haven't found it yet. The simplest solution I can think of so far would be the following:
NSString *myAddress = #"210 Queen Street East Brampton"; // or whatever the current address is
NSArray *components = [myAddress componentsSeparatedByString:#" "];
// this will strip the words out;
NSString *addressForURL = [components componentsJoinedByString:#"+"];
This should return addressForURL as 210+Queen+Street+East+Brampton. If there is more you need to do with it, this should at least give you a base to start from
I want to know the serial number of my iPhone using my application. I have writen code below.
- (NSString*)getSerialNumber
{
CFTypeRef serialNumberAsCFString;
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert)
{
serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
}
IOObjectRelease(platformExpert);
NSString *serial = [[NSString alloc] initWithFormat:#"%#",serialNumberAsCFString];
NSLog(#"serail no==>%#",serialNumberAsCFString);
NSLog(#"serail no==>%#",serial);
}
Why am I still getting wrong serial number?
You should change the argument 2 of IORegistryEntryCreateCFProperty from CFSTR (kIOPlatformUUIDKey) to CFSTR (kIOPlatformSerialNumberKey). Then you will get the correct serial number(with length of 11 characters).
Are you linking the IOKit framework?
Try the
id getValue(NSString *iosearch);
function, available at
http://blogs.oreilly.com/iphone/2008/08/retrieving-device-information.html
You can also use the UIDevice class to retrieve other useful information
For instance, you can do:
NSString *id = [[UIDevice currentDevice] uniqueIdentifier];
Other useful properties are the following ones:
name
systemName
systemVersion
model
localizedModel
Ready to use category on UIDevice: UIDevice+serialNumber. Not sure this would be accepted on the App Store.