Appboy / appboy-ios-sdk

Public repo for the Braze iOS SDK
https://www.braze.com
Other
164 stars 142 forks source link

[Bug]: Geofence not working at all #348

Closed hendych closed 1 year ago

hendych commented 1 year ago

Platform

iOS

Platform Version

iOS 14.5

Braze SDK Version

4.4.4

Xcode Version

13.3

Integration Method

Cocoapods

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

Following this guideline https://www.braze.com/docs/developer_guide/platform_integration_guides/ios/advanced_use_cases/locations_and_geofences/

  1. Background push notification enabled.

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[Appboy sharedInstance] registerApplication:application
                    didReceiveRemoteNotification:userInfo
                          fetchCompletionHandler:completionHandler];
    
    if ([ABKPushUtils isGeofencesSyncRemoteNotification:userInfo]) {
        return;
    }
    }
    Screen Shot 2022-10-17 at 23 58 27
  2. Location did request always authorize. https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization?language=objc

    func requestAuthorization() {
        if self.locationManager.responds(to: #selector(CLLocationManager.requestWhenInUseAuthorization)) {
            self.locationManager.requestWhenInUseAuthorization()
        }
    
        if LocationManager.getCurrentAuthorizationStatus() == .authorizedWhenInUse && self.locationManager.responds(to: #selector(CLLocationManager.requestAlwaysAuthorization)) {
            self.locationManager.requestAlwaysAuthorization()
        }
    }
  3. Init Braze SDK with geofence enabled.

    [Appboy startWithApiKey:self.brazeAPIKey
              inApplication:[UIApplication sharedApplication]
          withLaunchOptions:launchOptions
          withAppboyOptions:@{
              ABKPushStoryAppGroupKey: xxx,
              ABKMinimumTriggerTimeIntervalKey: @(10)
              ABKEnableGeofencesKey: @(YES),
              ABKDisableAutomaticGeofenceRequestsKey: @(YES),
          }];
  4. Geofence enabled in settings.

  5. Use manual request geofence.

Expected Behavior

User location is recorded through User Search option

Actual Incorrect Behavior

Nothing happens, no location data.

Screen Shot 2022-10-17 at 23 59 01

Verbose Logs

No response

Additional Information

How is this work with manual request? Manual request params need lat and lon, and why it needs location 'authorization always'?

Is the SDK request to the Braze BE and then go back to device through silent push notification?

Please... your documentation lack details and troubleshooting articles.

hokstuff commented 1 year ago

Hi @hendych,

Are you making this method call to request for Geofences? When you make that request, it asks the server if there are any geofences on the server for that particular location, but it won't update the user profile to say that they are at that particular location. If you want to store a particular location for a user, you can use logSingleLocation.

It is currently a known limitation that the Geofences feature is only supported with Always authorization enabled for the ObjC SDK (however, on the Swift SDK, Geofences are supported under both WhenInUse and Always). Once the Geofences setup is completed and the device is synced with the latest Geofence objects, if the end user's device enters a geofence, the Braze SDK will be able to respond accordingly (via triggering an in-app message, sending that info to the backend, etc).

For more information, feel free to look at our example app which contains examples of how to successfully integrate our Geofences feature. To help with debugging your integration, please contact support@braze.com for more streamlined support, and we will be able to help you further by asking for specific integration code, verbose logging to see what is happening in your app, etc.

Thanks!

hendych commented 1 year ago

Hi @hendych,

Are you making this method call to request for Geofences? When you make that request, it asks the server if there are any geofences on the server for that particular location, but it won't update the user profile to say that they are at that particular location. If you want to store a particular location for a user, you can use logSingleLocation.

It is currently a known limitation that the Geofences feature is only supported with Always authorization enabled for the ObjC SDK (however, on the Swift SDK, Geofences are supported under both WhenInUse and Always). Once the Geofences setup is completed and the device is synced with the latest Geofence objects, if the end user's device enters a geofence, the Braze SDK will be able to respond accordingly (via triggering an in-app message, sending that info to the backend, etc).

For more information, feel free to look at our example app which contains examples of how to successfully integrate our Geofences feature. To help with debugging your integration, please contact support@braze.com for more streamlined support, and we will be able to help you further by asking for specific integration code, verbose logging to see what is happening in your app, etc.

Thanks!

Hi @hokstuff thank you for your detailed response! So it won't log any location, omg I looked for days why it didn't log my location lol. So from your response the best way to use the geofence is to use swift SDK so it supports both whenInUse or Always auth.