How would draw a walking route by two point (start and end).
I wont use polyline.
Please check following tutorial Draw Route Between two points Also Check BreadCrumb example of Apple hope its helps to you!
You're not allowed to use google directions within your app. The only way you can do this is to send them to the google maps application as per:
- (void)getDirections {
CLLocationCoordinate2D start = { (startLatitude), (startLongitude) };
CLLocationCoordinate2D end = { (endLatitude), (endLongitude) };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&dirflg=w", start.latitude, start.longitude, end.latitude, end.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
Related
I am using webview in one of OS X app and got strange requirement from client that:
1) Need to show address bar in app for webview, I tried if there's any support by webview but couldn't really find. I know I can do that by having a text field and show URL in that but I am not sure if that's the right way so is there any other better way, please suggest.
2) Need to also check whether loaded URL has SSL support and show some icon like padlock (open/close). So again is there any support or feature of Webview that i can use or I just have to check for URL prefix of http or https? Please help.
Thanks in advance.
MP
That is exactly what you should do. Create the text field, and insert this bit of code into your application:
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:#"window.location"];
[myTextField setStringValue:currentURL];
}
For the second part of your question, use the currentURL string, and check if https:// exists in the string using the NSNotFound method. By using [myString rangeOfString:#"string_to_search_for"].location != NSNotFound, it will return true if the rangeOfString: is found. (!= means not equal to.) (So != NSNotFound means that your rangeOfString is not equal to not being found... if that makes sense)
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:#"window.location"];
if ([currentURL rangeOfString:#"https://"].location != NSNotFound) {
// *https://* exists! Show your closed padlock image!
} else {
// *https://* does not exist. Show your open padlock image.
}
}
Hope this was helpful!
I have created an NSTokenField in my xib. I'd like to display tokens with different colors inside that tokenField. Meaning: some tokens will be blue, the rest will be red (according to their content). Is that possible?
The following code doesn't work for me. I hope someone can help me out:
- (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString:(NSString *)editingString
{
id returnRepresentedObject = nil;
NSTokenFieldCell *tf = [[NSTokenFieldCell alloc] init];
tf.stringValue = editingString;
tf.backgroundColor = [NSColor redColor];
returnRepresentedObject = tf;
return returnRepresentedObject;
}
Result: all tokens remain blue... :-(
Any help will be highly appreciated!
Its possible by using private APIs. Subclass NSTokenAttachmentCell (Private) and NSTokenFieldCell.
Sample project
Use BWTokenAttachmentCell and BWTokenFieldCell class and NSTokenAttachmentCell class dump from BWToolkit. Modify initialize method of BWTokenAttachmentCell.
[sample project
NOTE:
Use this method if you are not targeting for Mac App Store.
You'll probably have to role your own. There is a wwdc video from 2010 about advanced Cocoa Text handling. The NSTokenField Uses NSTextAttachments to render the tokens.
I have been drawing routes in iOS5, but as the app has to be upgraded to iOS6, it does not allow to draw routes between coordinate locations . I have searched a lot, but ended up in vain. Can anyone help me on which api to use in iOS6 since google maps doesnt support anymore ???
EDIT : I have used Google iOS SDK previously to plot the routes which will auto take care of the polylines. As far as I have searched, i will be able to redirect to browser to show routes and navigation. But i need to draw this in-app [ iOS6 ]. Does iOS6 automatically does the routing, if so can u pls share some code to get a gist of it. This code sample I used it in iOS5 using google maps
// over lay map to draw route
routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:routeMapView];
diretions = [UICGDirections sharedDirections];
UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init];
//setting travel mode to driving
options.travelMode = UICGTravelModeDriving;
[diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];
// Overlay polylines
UICGPolyline *polyline = [directions polyline];
NSArray *routePoints = [polyline routePoints];
NSLog(#"routePoints %#",routePoints);
[routeOverlayView setRoutes:routePoints];
I did route in my application. I used The Google Geocoding API (used for iOS 6 only) https://developers.google.com/maps/documentation/geocoding/
Something like this:
- (void) sendRequestForLat: (CGFloat) lat lon: (CGFloat) lon
{
NSString* request;
NSInteger zoom = 12;
NSString* location = [NSString stringWithFormat: #"%f,%f", lat, lon];
NSString* daddr = [NSString stringWithFormat: #"%f,%f", myLat, myLon];
request = [NSString stringWithFormat: #"saddr=%#&daddr=%#&zoom=%i&directionsmode=walking", location, daddr, zoom];
NSString* typeMapsApp = isGoogleMapsAppPresent ? #"comgoogle" : #"";
NSString* urlString = [NSString stringWithFormat: #"%#maps://?%#", typeMapsApp, request];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];
}
You're using a third party piece of code to do your route drawing, rather than using MapKit itself. The library you're using (which I found on GitHub here) hasn't been updated for two years.
I'd recommend you move away from that library to something more current. If you want you could consider using Google's iOS Map SDK, which supports iOS 6 (link here). You could combine this with Google's Directions API to draw polylines directly onto the map. Or you could stick with MKMapView, and again draw directly onto the map with polylines.
It's not that iOS has changed how it draws polylines onto a map - it's that the third-party code you're using is out of date.
Is there any Mac App Store compliant way of setting the desktop wallpaper position to "Stretch to Fill Screen"?
This code sample from Apple provides a good overview of the problem and how to properly code for it in Cocoa. The salient code snippet appears to be the following:
- (void)updateScreenOptions:(NSScreen*)screen
{
if (screen)
{
NSDictionary *screenOptions = [[NSWorkspace sharedWorkspace] desktopImageOptionsForScreen:curScreen];
// the value is an NSNumber containing an NSImageScaling (scaling factor)
NSNumber *scalingFactor = [screenOptions objectForKey:NSWorkspaceDesktopImageScalingKey];
[scalingPopup selectItemAtIndex:[scalingFactor integerValue]];
// the value is an NSNumber containing a BOOL (allow clipping)
NSNumber *allowClipping = [screenOptions objectForKey:NSWorkspaceDesktopImageAllowClippingKey];
[[clippingCheckbox cell] setState:[allowClipping boolValue]];
// the value is an NSColor (fill color)
NSColor *fillColorValue = [screenOptions objectForKey:NSWorkspaceDesktopImageFillColorKey];
if (fillColorValue)
[fillColor setColor:fillColorValue];
}
}
As mentioned in some of the answer errata, the correct method calls here to resolve your question appear to be [screenOptions setObject:scalingFactor forKey:NSWorkspaceDesktopImageScalingKey] and [[NSWorkspace sharedWorkspace] setDesktopImageURL:imageURL forScreen:curScreen options:screenOptions error:&error], which should provide the desired functionality.
I freely admit this was a collaborative effort, but it seems we've blundered through to a correct solution.
(Additional information on the NSImageScaling enumeration and NSWorkspace, which contains the correct scaling keys.)
Unfortunately there is no Mac App Store compliant way of setting the desktop image options. They only methods available with regards to desktop images are:
– desktopImageURLForScreen:
– setDesktopImageURL:forScreen:options:error:
– desktopImageOptionsForScreen:
You may be able to do it by executing an AppleScript, though I do not think Apple will like that.
Hope this helps!
EDIT:
[screenOptions setObject:scalingFactor forKey:NSWorkspaceDesktopImageScalingKey];
[[NSWorkspace sharedWorkspace] setDesktopImageURL:imageURL forScreen:curScreen options:screenOptions error:&error];
Is there a way (some API) to get the list of installed apps on an iPhone device.
While searching for similar questions, I found some thing related to url registration, but I think there must be some API to do this, as I don't want to do any thing with the app, I just want the list.
No, apps are sandboxed and Apple-accepted APIs do not include anything that would let you do that.
You can, however, test whether a certain app is installed:
if the app is known to handle URLs of a certain type
by using [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"thisapp://foo"]
You can get a list of apps and URL schemes from here.
For jailbroken devices you can use next snipped of code:
-(void)appInstalledList
{
static NSString* const path = #"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist";
NSDictionary *cacheDict = nil;
BOOL isDir = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir)
{
cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
NSDictionary *system = [cacheDict objectForKey: #"System"]; // First check all system (jailbroken) apps
for (NSString *key in system)
{
NSLog(#"%#",key);
}
NSDictionary *user = [cacheDict objectForKey: #"User"]; // Then all the user (App Store /var/mobile/Applications) apps
for (NSString *key in user)
{
NSLog(#"%#",key);
}
return;
}
NSLog(#"can not find installed app plist");
}
for non jailbroken device, we can use third party framework which is called "ihaspp", also its free and apple accepted. Also they given good documentation how to integrate and how to use. May be this would be helpful to you. Good luck!!
https://github.com/danielamitay/iHasApp
You could do this by using the following:
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector = NSSelectorFromString(#"defaultWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];
SEL selectorALL = NSSelectorFromString(#"allApplications");
NSMutableArray *Allapps = [workspace performSelector:selectorALL];
NSLog(#"apps: %#", Allapps);
And then by accessing each element and splitting it you can get your app name, and even the Bundle Identifier, too.
Well, not sure if this was available back when the last answer was given or not (Prior to iOS 6)
Also this one is time intensive, yet simple:
Go into settings > Gen. >usage. The first category under usage at least right now is Storage.
It will show a partial list of apps. At the bottom of this partial list is a button that says "show all apps".
Tap that and you'll have to go through screen by screen, and take screenshots (Quick lock button and home button takes a screenshot).
I'm doing this now and I have hundreds of apps on my iPhone. So it's going to take me a while. But at least at the end of the process I'll have Images of all my apps.