iOS Question B4i Location Services

Marcos Alves

Well-Known Member
Licensed User
Hello All,

I'm using this sample code to implement location services in an app: https://www.b4x.com/android/forum/threads/location-gps.46148/#content

I notice that, in the sample, when locManager.Initialize("LocManager") is called , Iphone automatically shows a message requesting authorization on screen and after user select the event LocManager_AuthorizationStatusChanged is raised.
I replicated the code in my app but the request authorization message isn't being opened and instantly after LocaManager.initialize the event LocManager_AuthorizationStatusChanged (Status As Int) shows locManager.IsAuthorized = false. I already reseted the authorizations of iPhone but it's still happening . Sample app runs fine.
Is there any additional configuration that I'm eventually missing?

PlistExtra is added:
B4X:
    #PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Sua localização será acessada somente agora para buscarmos os melhores estabelecimentos perto de você.</string>
       #PlistExtra:<key>NSLocationUsageDescription</key><string>Sua localização será acessada somente agora para buscarmos os melhores estabelecimentos perto de você.</string>

And the code of the module that requests location is:

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private addressList As CustomListView
    Private imgGps As ImageView
    Private lblGps As Label
    Private txtAddress As TextField
    Dim timer1 As Timer

#if B4i
    Private hud1 As HUD
    Private locManager As LocationManager
#End If
   
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("addressSelectLayout")
    timer1.Initialize("timer1",2000)
   
    addressList.Clear
   
End Sub

Private Sub lblGps_Click   <---- location is required when the user clicks a label.
   
    #if B4i
        locManager.Initialize("LocManager")  
    #end if  
   
End Sub

#if B4i
Private Sub LocManager_AuthorizationStatusChanged (Status As Int)
   
    Log("Autorizado location -> " & locManager.IsAuthorized)
    locManager.Stop
   
End Sub
#end if
 

Marcos Alves

Well-Known Member
Licensed User
Uninstall the existing app and try it again. Maybe you somehow declined the permission in the past. You can also see it in the default settings app.
I already uninstalled and the result is still false. I also cleaned app authorizations in general -> Reset -> Reset Location and Privacy ... all iPhone apps are requiring authorization again when opened but this one doesn't show any request window and remains false for location in the code log...
I thought that could be something related to the certificate that I'm using in Apple... I already changed the app to the name without wildcard in order to implement Firebase Cloud Messages (which the app uses also). Is there any configuration to previously define the location authorization in the certificate in Apple developer console?
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Uninstall the existing app and try it again. Maybe you somehow declined the permission in the past. You can also see it in the default settings app.
Update... one interesting information: in the other apps those use location, even when I don't allow there is a reference to location services in app permission in settings panel... I think that iPhone recognizes that location library is present in app and gives to the user the option to enable it (the sample app is shown in settings for location also). But this app isn't showed in location options in iPhone - somehow iPhone doesn't recognizes the location library in it. Why ?
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Uninstall the existing app and try it again. Maybe you somehow declined the permission in the past. You can also see it in the default settings app.
Ok, I give up... tested everything. The locationmanager library is very simple and I really don't know anymore where is the problem. @Erel , if you can check it, I can send to you the code to test. Maybe there is something new in IOS permissions that I lost. I don't know...
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Ok, I give up... tested everything. The locationmanager library is very simple and I really don't know anymore where is the problem. @Erel , if you can check it, I can send to you the code to test. Maybe there is something new in IOS permissions that I lost. I don't know...
Never mind ! :) I created a new app only with the location Library and didn't worked also!!! Comparing with the original sample project I added events and resources related to location one by one and the request box only was showed after the addition of all the events related to locationManager library!!!
That's what I get... I don't know if the conclusion is correct but I think that it is an important observation:
"The app using locationManager in IOS only will be labeled with location authorization resources if all locationManager events are created in the same class that the library is initialized".
I don't know if the conclusion is correct but that's what I get. I don't know if I'm wrong @Erel ... Thanks for your fantastic support and help as always 👏
 
Upvote 0

roumei

Active Member
Licensed User
I'm not sure if your code in post #1 is complete but you need to call LocManager.Start as shown in Erel's example to make the permission dialog appear.
B4X:
LocManager.Initialize("LocManager")
LocManager.Start(0)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
I'm not sure if your code in post #1 is complete but you need to call LocManager.Start as shown in Erel's example to make the permission dialog appear.
B4X:
LocManager.Initialize("LocManager")
LocManager.Start(0)
Thanks @roumei . I tested with start(0) also... the problem was: before I put all the events in the routine I didn't even see the app in the iPhone's apps list with location capabilities... the app appeared in iPhone location authorization list after I add the events. That's what happened.
 
Upvote 0

roumei

Active Member
Licensed User
I don't think the events are needed to show the permission dialog or to list the app in the privacy settings. This is a minimal example of what is sufficient to show the dialog on iOS 14.4 (you'll need the events for a fully functional app, though):
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private LocManager As LocationManager
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub Button1_Click
    LocManager.Initialize("LocManager")
    LocManager.Start(0)
End Sub
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
I don't think the events are needed to show the permission dialog or to list the app in the privacy settings. This is a minimal example of what is sufficient to show the dialog on iOS 14.4 (you'll need the events for a fully functional app, though):
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private LocManager As LocationManager
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub Button1_Click
    LocManager.Initialize("LocManager")
    LocManager.Start(0)
End Sub
I'll do some additional tests but that was the behavior I got in my project...
 
Upvote 0
Top