turn-by-turn navigation with google maps url scheme swift - swift

How can I enable turn-by-turn navigation with google maps urlscheme?. I used below url in swift
comgooglemaps://?saddr=%f,%f&daddr=%f,%f&directionsmode=driving
but it only creates a route, the start navigation button is not present when the google maps app is activated.
am i missing something?
let kGoogleMapsSchema = "comgooglemaps://"
let path = "\(kGoogleMapsSchema)?saddr=%f,%f&daddr=%f,%f&directionsmode=driving"
guard let finalURLString = String(format: path, currentUserCoordinates!.latitude, currentUserCoordinates!.longitude, destinationCoordinates!.latitude, destinationCoordinates!.longitude, currentUserCoordinates!.latitude, currentUserCoordinates!.longitude).addingPercentEncoding(
withAllowedCharacters: .urlQueryAllowed) else {
return
}
guard let url = URL(string: finalURLString) else {
return
}
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
am i missing something?

I found the answer as only preview button was available instead of start navigation. Because I was giving start coordinates not of my current location. So in case it is my current coordinates it will work.
Google Maps, No Option for Starting the Navigation, Only Preview is there

Related

How to receive image dragged from Safari webpage with SwiftUI `.onDrop()`

I'm not able to receive image dragged from Safari webpage in my SwiftUI app on macOS. I suppose Safari uses different mechanics, because it works properly when it comes to Chrome and Firefox. I use .onDrop() but it results empty providers no matter what kind of UTType used. Below is my code but output no provider available.
So, what UTType it is when dragging image from Safari webpage, and how can I implement it in .onDrop()
.onDrop(of: [.url, .fileURL], isTargeted: $isTarget) { providers -> Bool in
if let provider = providers.first,
let identifier = provider.registeredTypeIdentifiers.first {
print(identifier)
provider.loadItem(forTypeIdentifier: identifier) { data, error in
// Do something here
}
} else {
print("no provider available")
}
return true
}

How to center my window in another application's window?

My application is distributed via App Store (just to let you know about some limitations). I would like to center my application in the frontmost app window. Is it possible?
The only thing I need to know is the frame of the frontmost application. I checked NSWorkspace.shared.frontmostApplication but there is nothing about the window's position.
I found a solution for that. It looks like it doesn't even require Accessibility permission.
if let activeApp = NSWorkspace.shared.frontmostApplication {
(CGWindowListCopyWindowInfo([.excludeDesktopElements, .optionOnScreenOnly], kCGNullWindowID) as [AnyObject]?)?
.first { $0.object(forKey: kCGWindowOwnerPID) as? pid_t == activeApp.processIdentifier }
.flatMap { $0.object(forKey: kCGWindowBounds) as CFDictionary? }?
.flatMap {
guard let bounds = CGRect(dictionaryRepresentation: $0) else { return }
print("Active window bounds: \(bounds)")
}
}
Also, keep in mind:
The coordinates of the rectangle are specified in screen space, where the origin is in the upper-left corner of the main display.

App Store link "rate the application" in SwiftUI

I just updated my "Rate the application" button that I'm using in all my apps. Actually, I would prefer to get not only a rating but a rating + a comment.
So I replaced this:
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
}
By this:
let url = URL(string: "https://apps.apple.com/app/(AppName)/(AppID)?action=write-review")!
UIApplication.shared.open(url)
And it's working perfectly fine!
But now, I'm wondering what should I do about the "encryption request" from Apple? Some people say there's no need for a "https" call to the App Store but Apple says a bit different: https://help.apple.com/app-store-connect/#/dev88f5c7bf9
What you guys are doing? Did you asked a document from the BIS or not?

Disable the loading of Stylesheets in UIWebView and/or WKWebView

I have absolutely tried everything with this one. I've read every apple article and no where can I find how to disable the loading of CSS (Styling) in the legacy UIWebView or the new WKWebView. I don't mind what web view I use just as long as it can accomplish this.
I've tried WKPreferences() and WKWebViewConfiguration and both have no member userStyleSheetEnabled.
I've referred myself to this apple article https://developer.apple.com/documentation/webkit/webpreferences/1536396-userstylesheetenabled?
Does anyone know the answer and how to achieve this on Swift 4?
The WebView class you referenced is very old and has been deprecated. If you need to add a webview to your app, use WKWebView instead. This answer works with iOS >= 11 and macOS >= 10.13.
What you need is adding WKContentRuleList to your WKWebView's configuration. They are similar to Safari content blockers (i.e. ad-blockers) that you may already have installed on your phone:
// This should ideally be in a file but we're using string for convenience
let jsonRuleList = """
[{
"trigger": {
"url-filter": ".*",
"resource-type": ["style-sheet"]
},
"action": {
"type": "block"
}
}]
"""
// Compile the content-blocking list
WKContentRuleListStore.default().compileContentRuleList(forIdentifier: "blockStyleSheet", encodedContentRuleList: jsonRuleList) { list, error in
guard error == nil else { print(error!.localizedDescription); return }
guard let list = list else { return }
// Add the stylesheet-blocker to your webview's configuration
let configuration = WKWebViewConfiguration()
configuration.userContentController.add(list)
// Adding the webview to the view. Nothing to see here
self.webView = WKWebView(frame: self.view.bounds, configuration: configuration)
self.view.addSubview(self.webView)
// Let's try Apple's website without CSS
let request = URLRequest(url: URL(string: "https://www.apple.com")!)
self.webView.load(request)
}
Result:
References
Customized Loading in WKWebView (WWDC video)
Creating Safari Content-Blocking Rules

How to load google street view in a UIWebView of iphone app?

I am trying to use the google map street view in my app, so i am trying to load the html file in my Webview. but it is need the flash player to show the street view.
Is adobe flash player is required for this?
Anyone know how to use the street view in our iphone app?
Regards,
Yes, it is possible to load Google StreetView in UIWebView. Here is a sample code example to load Google StreetView -
let urlAddress = "http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";
let request = NSURLRequest(URL: NSURL(string: urlAddress)!)
glWebView.loadRequest(request)
After loading this streetView. Google will give you an alert that this URL is belongs to google map only. To hide that alert message just add this below javascript query in your WebViewDidFinish method -
webView.stringByEvaluatingJavaScriptFromString("document.getElementsByClassName('ml-unsupported-link-dialog-container')[0].style.display='none'")
Well technically it is not possible, but if you can get the panorama image id for that specific latitude and longitude, then it is possible. In my previous answer, I said it is possible as because I know the panorama id for that specific location. Using that code you can open steetview in your UIWebview, but it will show a warning. By touching anywhere in your webview will disappear that warning alert.
Bu Google introduce there SDK to load streetview in your iOS app, instead of leaving your app. All you need to do is add 'GoogleMaps' sdk using cocoa pods and run this below source code to display google Streetview for specific latitude and longitude.
let panoSvc = GMSPanoramaService()
panoSvc.requestPanoramaNearCoordinate(CLLocationCoordinate2D(latitude: 32.847683, longitude: -96.771638), radius:100, callback: { (panorama, error) in
if error == nil {
DispatchQueue.main.async(execute: {
let panoView = GMSPanoramaView(frame: .zero)
self.view = panoView
panoView.moveNearCoordinate((panorama?.coordinate)!, radius: 200)
print("Panorama ID: ", panorama?.panoramaID)
print("Panorama Co-ordinate: ", panorama?.coordinate)
})
}
else {
Utility.showCustomMsg(self.view, label: "Not Found", detailslbl:"Street View is not available for this location.", isSuccessImg: false, duration: 3)
{
self.navigationController?.popViewController(animated: true)
}
}
})
Cool huh...... Thanks goes to Google for their cool staff.