I have a very simple application that uses realtime location data to obtain relevant information, developed in C# as a UWP 10.0 application.
My interaction with the geolocation API is very simple: I only checked Location in the "Package Manifest" under "Capabilities" and I only use the following API call:
var locator = new Windows.Devices.Geolocation.Geolocator();
var location = await locator.GetGeopositionAsync();
When this call is first made, Windows 10 throws up an "Allow this application to use your precise location [yes | no]" dialog. Selecting "yes" seems to "save" this choice for around 5 minutes or so; subsequent attempts at obtaining the user's position within the next five minutes go through (I believe they return the cached value, as it never seems to change), but more than 5 minutes later, the permission dialog is always shown once more (even though the user has already authorized it).
From my reading of the geolocation API documentation on MSDN, I can find nothing to suggest that this is the intended behavior. Under privacy settings in the metro control panel, this application is under the list of apps allowed to use the precise location. What's more, other apps in that list with precise location enabled have never prompted me to allow them access to the precise location past the first time.
What am I doing wrong here and how can I prevent this dialog from constantly popping up?
EDIT
With await Geolocator.RequestAccessAsync(), the permissions are cached so long as the exe is not modified/re-compiled.
I was able to replicate your problem. But according to official documentation, it clearly mentions, that you need to call RequestAccessAsync() before any calls.
So when I made change from your lines of codes, to below, permission Request window showed up only once and subsequent calls were made directly.
GeolocationAccessStatus accessStatus = await Geolocator.RequestAccessAsync();
if (accessStatus == GeolocationAccessStatus.Allowed)
{
Geolocator locator = new Geolocator();
Geoposition location = await locator.GetGeopositionAsync();
locText.Text = location.Coordinate.Point.Position.Latitude + Environment.NewLine + location.Coordinate.Point.Position.Longitude;
}
Related
I have the following code to open Navigation App from one of the button click in my content page.
var location = new Location(Convert.ToDouble(jobItem.Latitude), Convert.ToDouble(jobItem.Longitude));
var options = new MapLaunchOptions { NavigationMode = NavigationMode.Driving };
await Map.OpenAsync(location, options);
There are Google Maps and Waze in my android phone, so the code above did show the selection panel and let user to choose which app to use which is no issue. However, when this meet iOS, it straight away open Apple Maps without any selection even though there are 3 navigation apps in the iPhone. I have tried to research to deal with the default navigation app setting on iOS but unfortunately iOS didn't provide any single option to set the app as default unlike android. What else I can do?
You could use the Xamarin.Essentials: Launcher NuGet package.
You'd need to modify the code to look something like the below pseudocode
var supportsWaze = await Launcher.CanOpenAsync("whateverTheWazeUriSchemeIs://");
var supportsGoogleMaps = await Launcher.CanOpenAsync("whateverTheUriSchemeIs://");
You'd then need to give the user some sort of UI for them to select a mapping app based upon these boolean(s) being true. I'd use an ActionSheet
Then you can use the await Launcher.OpenAsync method to open the correct URI based on whatever choice the user made. You could offer them the option to remember this choice for later as well.
iOS wont allow you to override the OS default apps, but within your own app you can choose how other applications are launched. The Google applications are a good example of this.
I use Branch to create deep links. I added a new control parameter ios_has_app_url and ios_url. Clicking on the deep link when the application is installed then everything works correctly, but if you click on the deep link when the application is not installed on the device then during startup, I see that the browser instead of opening ios_url (App Store link), it tries to open ios_has_app_url. How can I fix it?
private func createDeepLink(_ card: CardModel) -> (branchUniversalObject: BranchUniversalObject, branchLinkProperties: BranchLinkProperties) {
let branchUniversalObject = BranchUniversalObject(canonicalIdentifier: ("cardId/\(card.id)"))
branchUniversalObject.title = card.title
branchUniversalObject.contentDescription = ""
branchUniversalObject.imageUrl = card.photoURLsProperties.originalURL
branchUniversalObject.addMetadataKey(CardKeys.cardID.rawValue, value: card.id)
branchUniversalObject.addMetadataKey("placeAvatarURLString", value: card.photoURLsProperties.originalURL)
branchUniversalObject.addMetadataKey("title", value: card.title)
branchUniversalObject.addMetadataKey("isAutoGeneratedCard", value: "false")
let fullLocationName = card.location.fullLocationName
branchUniversalObject.addMetadataKey("fullLocationName", value: fullLocationName)
branchUniversalObject.addMetadataKey(CardKeys.ownerID.rawValue, value: card.ownerID)
branchUniversalObject.addMetadataKey(ParametersKeywords.type.rawValue, value: ModeKeywords.shareCard.rawValue)
branchUniversalObject.addMetadataKey("availableSeats", value: card.peopleProperties.availableSeats.description)
let coordinate = card.location.coordinate
branchUniversalObject.addMetadataKey("latitude", value: coordinate.latitude.description)
branchUniversalObject.addMetadataKey("longitude",value: coordinate.longitude.description)
let linkProperties = BranchLinkProperties()
linkProperties.feature = "sharing"
linkProperties.addControlParam("$desktop_url", withValue: "http://www.appname.com")
linkProperties.addControlParam("$ios_has_app_url", withValue: "appname://")
linkProperties.addControlParam("$ios_url", withValue: "https://itunes.apple.com/app/idXXXXXXXXXXXXXXX")
return (branchUniversalObject: branchUniversalObject, branchLinkProperties: linkProperties)
}
Update: My goal is that when the deep link is clicked, if the application is installed, then the application is opened, if not, then the app store link.
Update 1: I changed my code like this and it opens the App Store if I just click on the link, and if I use 3D Touch then I can choose where to open this link. Is it possible to do that if the application is installed and clicking on the link immediately opened the application (or at least a link in the browser, but that there was an option to open the application) and if the application is not installed, then clicking on the link, go to the App Store app page .
let linkProperties = BranchLinkProperties()
linkProperties.feature = "sharing"
linkProperties.addControlParam("$desktop_url", withValue: "http://www.appname.com")
linkProperties.addControlParam("$ios_has_app_url", withValue: "https://appname.app.link/")
linkProperties.addControlParam("$ios_url", withValue: "itms-apps://itunes.apple.com/app/idXXXXXX")
Alex from Branch.io here:
The good news is this is much easier than you're expecting. However, since you made such a complete report, I'll go through all the details so you know exactly what happens behind the scenes.
Short Explanation
To handle launching your app when it is installed, you don't need to manually set your custom URI scheme as the value of $ios_has_app_url — Branch and iOS implement this behavior for you by design.
If your links are not launching your app, you may have a problem with your Universal Links configuration. I recommend reviewing this troubleshooting guide.
Long Explanation
Our $ios_has_app_url control parameter relies on a boolean has_app value tracked by our servers. The has_app value fairly accurate in typical real-world use (plenty good enough for switching a button between displaying an Open or an Install label on a smart app banner, for example), but it's not 100% accurate in all situations.
This is a limitation of iOS: Apple doesn't allow web pages to query for which apps are installed on a device (for obvious privacy reasons), so Branch has to rely on cookie matching. This means if we can't match the cookie, or haven't seen the user recently, or the user clears their device cache, or the user has uninstalled the app since the last time Branch saw them, the value of has_app will be incorrect. When the has_app value is incorrect, then the $ios_has_app_url behavior will also be wrong.
HOWEVER, even though Apple doesn't allow web pages to query access this data, iOS itself can still act on it. Universal Links do exactly this — when the user opens a Universal Link (which includes Branch links, assuming you got all the configuration done), the app will open if it is installed. If it is not installed, the user will be sent to the URL of the link.
Intended use of $ios_has_app_url
The Branch $ios_has_app_url parameter is intended for a very specific usecase in advanced implementations; the vast majority of our partners never use it. Here's the potential situation where you might want it:
You have an edge case where Universal Links are not supported, and you want to send your users to a different web page if Branch knows they have your app installed rather than giving them the option to open it. Obviously this is a rare situation, typically relevant only to enterprise-level apps.
Debugging has_app
If you're stuck trying to debug a situation where has_app is returning the wrong value, you have a couple of options:
If you're getting true and you want false, use Private Browsing mode in Safari. This prevents Branch from making a cookie match, meaning you will always get false.
Alternatively, follow these steps:
Ensure the app that is being tested has setDebug enabled.
Paste a link to a page with the smart banner code into Notes.
Uninstall the app.
Settings > General > Safari > Clear History and Website Data.
Settings > General > Safari > Advanced > Website Data > Swipe left and delete every entry.
Settings > General > Privacy > Advertising > Reset Advertising Identifier...
Click on the link in Notes (from step 1).
The banner should always show "Download" (when it does not, it is because clearing the Website Data was unsuccessful).
Tap on Download.
Run the app via Xcode (serves to install it).
Stop the app in Xcode, then launch it from the phone.
Click on the link in Notes again - the button should now show "Open" and open the app.
I see that the browser instead of opening ios_url (App Store link), it
tries to open ios_has_app_url. How can I fix it?
By letting the link to be:
"itms-apps://itunes.apple.com/app/idxxxxxxxxxx"
I have a Xamarin.iOS application where I am using this guide to make use of the CMPedometer floors ascended property. Here is some relevant code on my single view app:
CMPedometer pedometer;
...
public override async void ViewDidLoad(){
base.ViewDidLoad();
if (CMPedometer.IsFloorCountingAvailable)
{
pedometer = new CMPedometer();
//app crashes here:
pedometer.StartPedometerUpdates(new NSDate(), UpdatePedometerData);
var data = await pedometer.QueryPedometerDataAsync((NSDate)DateTime.SpecifyKind(DateTime.Now.AddHours(-24), DateTimeKind.Utc), (NSDate)DateTime.Now);
UpdatePedometerData(data, null);
}
}
My very basic app crashes when I try to get updates from my CMPedometer with little error output. This is what I get:
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
which may be an issue with my app permissions? If that's the case I am not sure how to grant/ask permissions on using the CDPedometer. Thanks for any help
Got this link. You have to add privacy setting for motion in your plist
https://blog.xamarin.com/new-ios-10-privacy-permission-settings/
Thanks to #panthor314 for getting me pointed in the right direction. Unfortunately the blog link above is dead, but this seems to be the new location for this information:
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/security-privacy?tabs=windows
This link explains:
Apps that fail to provide the required keys will be silently terminated by the system when they attempt to access one of the restricted features or user information, without error! If an app starts unexpectedly failing on iOS 10, ensure that all of the required Info.plist have been specified.
The relevant privacy key is NSMotionUsageDescription:
Motion Usage Description (NSMotionUsageDescription) - Allows the developer to describe why the app wants to access the device's accelerometer.
To add the property:
Right-click on Info.plist in your Solution Explorer (double click seems to open a different window)
Select Open With...
Select Generic PList Editor and click OK
At the end of the plist, click the + icon to add a new entry
Change Custom Property to Privacy - Motion Usage Description
Enter text to display to the user about accessing steps such as "This application would like to access your steps data"
Save the file and run the application again
I'm trying to automate the app , but suddenly in middle the google permissions window for permission like phone , location etc pops up , is there any way that I can make sure always permission pop ups are allowed
Try to set desired capabilities:
autoAcceptAlerts = true
Since you said google permissions, I am assuming you are dealing in Android. Also since there is no language tag, I am sticking to Java, you can frame the logic in any language you are using.
Well, its sad to inform you that currently there seems to be no such capability added for android. Though iOS has few similar capabilities.
So, for android what you can do is logically -
If these pop-ups are device dependent, change the device settings that these pop-ups are not allowed.
If these pop-ups are relevant to application permissions, then you must know when they would occur. Just keep a check -
List<WebElement> popUp = driver.findElement(<find the pop up using your locator strategy>);
if(popUp.size()!=0) {
WebElement accept/dismiss = driver.findElement(<find the button accordingly>);
accept/dismiss.click();
}
We are using Google Analytics to track events, but events don't appear to track 100% of the time. Sometimes they track, and sometimes they don't. We're not exceeding quota limits per session (at most we have 20 events per session). That shouldn't be the issue.
The tracking fails to work consistently on our normal website as well as our HTML5 mobile app version, though it's far less reliable with the HTML5 mobile app version.
Code:
var share_url = 'http://twitter.com/intent/tweet?text=';
// Log in GA
_gaq.push( ['_trackEvent', 'Share Twitter', ''] );
// Open URL in browser
open_external( share_url + encodeURIComponent( msg ) );
function open_external( url ) {
window.open( url + '#phonegap=external' );
}
_gaq.push( ['_trackEvent', 'Share Twitter', ''] );
This won't do anything.
For _trackEvent, the third argument (where you pass an empty string) is required. It's the 'Action' parameter. But an empty string is falsey, so it just fails silently.
Pass any value there, and it'll work.
Is this a reduced case? You shouldn't be seeing any events with that code.
Are you positive that you waited long enough for the data to be processed by Google? Especially since some tracking seems to be working.
I had the same behaviour (in a mobile app btw) but after waiting for more than a day it still came through. This still occurs on a daily basis... Hope this is the case for you too.
I'm not exactly sure what your problem can be, so I will throw some idea.
Most of them are obvious but it might help.
On your website:
Are you sure your embed the Google Analytics code snippet on every page who required tracking?
Load Google analytics from the asynchronous way.
On Google analytics check on Real time > Overview. As full report are delayed from few hours.
If you url is something like httq://localhost/ then your need to add the javascript code _gaq.push(['_setDomainName', 'none']); please read this post
It can't work with file:// url
(Probably not) Check if you can download the JavaScript from Google Analytics. Maybe your proxy block Google analytics tracking ?
In your application:
You are using embedded HTML 5 page within your app. So the way your open a page is using file://PATH_TO_MY_DIR/index.html as it's on your hard drive you can't send data to Google analytics.
As you are probably using PhoneGap, you need to "jump out" of your HTML page into native Objective-c code and send the event from your Objective-C code. Read Google Analytics and PhoneGap and this google group thread
Hope it help.
The problem is third parameter in:
_gaq.push( ['_trackEvent', 'Share Twitter', ''] );
The 2nd element of the array should be the category and the 3rd should be the action. For example:
_gaq.push( ['_trackEvent', 'Share', 'Twitter'] );
You can verify this yourself by pasting each of the above into your developer console (F12 in Chrome, Ctrl-Shift-K in Firefox) and watching the network traffic.
Reference:
https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEventTracking