[TIMOB-20002] iOS: Ti.Geolocation.requestLocationPermissions is not always called?
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-12-04T20:24:05.000+0000 |
Affected Version/s | Release 5.1.0 |
Fix Version/s | Release 5.1.2 |
Components | iOS |
Labels | geolocation |
Reporter | Fokke Zandbergen |
Assignee | Angel Petkov |
Created | 2015-11-17T11:10:49.000+0000 |
Updated | 2016-02-08T15:07:15.000+0000 |
Description
Both on device and in Simulator I can't get the callback for
requestLocationPermissions
in the following code to be called, even though - the first time - the dialog requesting permission *is* displayed. Which is weird, because in the [Ti 5.1.0 Sample App](https://github.com/appcelerator-developer-relations/appc-sample-ti510) it does call and is implemented in the exact same way. Removing everything in the button event listener except the request call doesn't change it either.
var win = Ti.UI.createWindow({
backgroundColor: 'white'
});
var btn = Ti.UI.createButton({
title: 'Request Permissions'
});
btn.addEventListener('click', function(e) {
Ti.API.info('Before Callback');
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
Ti.API.info('In Callback');
Ti.API.info(JSON.stringify(e, null, 2));
});
});
win.add(btn);
win.open();
*Notes:*
* Don't forget to add <key>NSLocationAlwaysUsageDescription</key><string>Deny or grant permission to test different scenarios.</string>
to the tiapp.xml
or use the attached project.
* For a clean slate either change the app id, reset the Simulator or just _Settings > General > Reset > Reset Location & Privacy_.
Attachments
File | Date | Size |
---|---|---|
requestdenied.zip | 2015-11-17T17:58:15.000+0000 | 10294306 |
Attached sample project.
Simplified test case in description and attached new project with that code. I've used the latest 5_1_X now (5.1.0.v20151116164430) and reset the Simulator and deleted
build
but still the same:Using code above, and with SDK 5.1.0.v20151116164430, I never get "In Callback" when I choose either approve or deny the request for permission.
[~emerriman] thanks for confirming I'm not crazy [~cng] I'm afraid this is a blocker :(
PR (master): https://github.com/appcelerator/titanium_mobile/pull/7460 PR (5_1_X): https://github.com/appcelerator/titanium_mobile/pull/7461 Summary: This issue is related to a bad practice (not checking already granted permissions). Anyway, this PR fixes that use-case.
Correct on that summary: Without this fix I can reproduce it with a clean build on a reset Simulator with a changed App ID as well so it's not related to a bad practice. More likely is it a result of the 3rd bullet of TIMOB-20004 where an empty string error message triggered the
errorMessage != nul
condition: https://github.com/appcelerator/titanium_mobile/pull/7461/files#diff-d8125f3a683a79e2b840cb8359e9d474L890Also covers the issues in TIMOB-20004, is the backport needed? Feels more like a 5.1.1 or 5.2.0 fix.
we'll keep the back port for 5.1.1.
PRs approved and merged.
Verified as fixed, Imported the attached sample app and built with SDK
5.1.1.v20151122191220
. Received the following in the console whenrequestLocationPermissions
is called:Tested on: Devices: iPhones 6S+ (9.1) Simulators: (9.1) & (8.4) Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.1.v20151122191220 Appc Studio: 4.4.0.201511182122 Appc NPM: 4.2.2 Appc CLI: 5.1.0-60 Alloy: 1.7.26 Xcode 7.1(7B91b) Node v0.12.7 *Closing Ticket.*
To Note: This ticket is marked 5.1.2 but PR was merged in 5.1.1GA
[~fokkezb] Just a quick rehash of this issue - it is happening when the permission is either allowed/denied before and then presenting requestLocationPermissions ?
When callback is nullified here https://github.com/hansemannn/titanium_mobile/blob/463fde3094356ae366a0ecd3e749779c1444c3f0/iphone/Classes/GeolocationModule.m#L890 The actual result of user approved/denied is never called because of condition here https://github.com/hansemannn/titanium_mobile/blob/463fde3094356ae366a0ecd3e749779c1444c3f0/iphone/Classes/GeolocationModule.m#L1080 Reopening the ticket.
master PR: https://github.com/appcelerator/titanium_mobile/pull/7526 5_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/7527 Additional test cases Case 1: Clear privacy settings. Shows permission alert and invokes callback *after* user acted on the alert. Case 2: Permission is either approved or denied earlier. Invokes callback. Permission alert is *not* shown.
CR and FT Passed. APPROVED! [~fokkezb] can you have a look as well before i merge? thanks!
PRs merged
[~ssombhatla] Testing your PR for release 5.1.2 : Case 1: Privacy settings are clear, upon clicking
Request Permissions
,Before Callback
is returned, and I am prompted to Allow or Deny Location Permissions. After selecting either,In Callback
is not returned. Case 2: With Permissions now Denied or Approved, clickingRequest Permissions
returns the following:Permission alert is not shown in this case. To clarify, is the expected result for *Case 1* as described above? or should the user receive the
In Callback
after denying / approving permission request? Tested with: iPhone 6s Plus Device (9.1) & Simulator (9.1), (8.4) Mac OSX El Capitan 10.11 (15A284) Studio: 4.4.0.201511241829 Ti SDK: 5.1.2.v20151202061227 Appc NPM: 4.2.2 App CLI: 5.1.0 Xcode 7.1(7B91b) Node v4.2.2 productionin Case 1, In callback should be returned. I'll check this again later.
[~htbryant] Sorry i was confused. in case 1, the callback will not be returned and that's the expected behavior. It's the same in 5.1.1.GA.
Now I'm confused [~cng], because case 1 was exactly why I created this ticket. The callback should be returned at all times.
Issue seems to be with not running on main thread which I was unable to emulated when running in Xcode. This PR should address the issue. PR master: https://github.com/appcelerator/titanium_mobile/pull/7539 PR 5_1_X: https://github.com/appcelerator/titanium_mobile/pull/7540
New PR: (Master) https://github.com/appcelerator/titanium_mobile/pull/7541. New PR :(5_1_X) : https://github.com/appcelerator/titanium_mobile/pull/7542 This will fix the issue where the callback will be called before the user grants/deny's permissions , the call back will now also display success if the user grants permission.
Verified as fixed, tested the sample code with sdk build
5.1.2.v20151206185250
and following callbacks are received: Case 1: Permissions GrantedCase 2: Permissions Denied
Before Callback
is returned once clicking "Request Permissions", andIn Callback
is returned after setting either Allow, or Don't Allow. Tested on: iPhone 6s Plus Device (9.1) & Simulators (9.1) , (8.4) Mac OSX El Capitan 10.11 (15A284) Studio: 4.4.0.201511241829 Ti SDK: 5.1.2.v20151206185250 Appc NPM: 4.2.2 App CLI: 5.1.0 Xcode 7.1(7B91b) Node v4.2.2 production *Closing ticket.*Callback is being invoked but on the wrong thread. Pull request discussion (https://github.com/appcelerator/titanium_mobile/pull/7597).
still facing this problem occasionally on SDK 5.1.2
Hello , are you able to reproduce the issue using the code presented above or your own ? If you are using your own could you please post it here and the steps required to reproduce it. Thank you! If the issue persists we'll re-evaluate the fix. Thank you!
can't find a way to reproduce so far, once I find it will update here, thanks
I've also seen it with 5.1.2.GA, where I was using it as a fallback in a timeout after monitoring for location changes (which don't fire if the user is not moving apparently). Could that be related since under the hood this method uses the same listener? https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/GeolocationModule.m#L580
I have this problem pretty consistently for Android 6.0 - and it also seems to work in the Ti 5.1.0 demo app... :-/ I first load the map and then call a function to verify the permissions - and parse a callback function to set the position if user has permission - or gives it (in which case it fails)
[~jda] This ticket is iOS related and fixed in 5.2.x, I think there is another one android-related, [~fokkezb] will be able to assist.
Ok, thanks Hans :-)