cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

addOrUpdate() is always successful but not truly adding fences (Xcode 9 and iOS 11) #248

Open Corebee opened 6 years ago

Corebee commented 6 years ago

Hey there,

i tried to get the geofence-plugin running on the latest Xcode 9 and iOS 11.
I can initialise the geofence-plugin without errors and can add fences without any errors.

But if I use the getWatched()-Method it always returns me 'undefined'.

Code: this.geofence.getWatched().then(function (geofencesJson) { var geofences = JSON.parse(geofencesJson); console.log('Data: ' + geofences.id + ', ' + geofences.latitude + ', ' + geofences.longitude); }

Provides: console.log: Data: undefined, undefined, undefined

Additional: JSON.stringify gives me that -> console.log: Data: "[]"

It looks like, the JSON-fences are not stored correctly by the addOrUpdate()-Method. So everytime the Transition should trigger, it cant find any fences to compare the position with.

To get the geofence-plugin with the current versions running I already did the following steps:

  1. Installed cordova-plugin-add-swift-support
  2. Installed cordova-plugin-geofence
  3. Initialising the plugin only when the platform is ready
  4. Removed the ios-platform and re-added
  5. Removed the Preference "UseLegacySwiftLanguageVersion"
  6. Added the Key NSLocationAlwaysAndWhenInUseUsageDescription to the Info.plist (for iOS 11)
  7. Updated the 3-Swift files as mentioned in https://github.com/cowbell/cordova-plugin-geofence/issues/215
  8. Also fixed this in the SwiftData.swift file - https://github.com/cowbell/cordova-plugin-geofence/pull/224/commits/283d4741168609381e4e8c94aceec78faf00ab31
  9. Converted the Swift-Files with Xcode (no errors)

Thanks for the help.

Regards

Software-Versions: Xcode: 9.0.1 Cordova: 7.0.1 Geofence: 0.7.0 Swift-Support: 1.7.0

dovk commented 6 years ago

I was able to get onTransactionRecieved() working after creating the .ipa with Xcode 9 on iOS 11. It worked at first but then stopped, it took a while to find that I had made a small change in my code that corrupted the json being passed to addOrUpdate - now it works. So as trivial as that might sound, it might be a similiar problem - perhaps monitor addOrUpdate() and take a look at the catch/error, it might be something like that. I added some specs towards the bottom of https://github.com/cowbell/cordova-plugin-geofence/issues/243

nilsk123 commented 6 years ago

Any update on this? have the exact same situation and problem

dovk commented 6 years ago

Did you check out what I did ? https://github.com/cowbell/cordova-plugin-geofence/issues/243 It’s been OK ever since

Corebee commented 6 years ago

For me, i ditched the geofence plugin completely for my project. It took so much time to find solutions for many problems with Swift 4.0 and the support for current issues was pretty rare. And also because of the reason there is a maximum of 20 geofences for iOS, and i definitely need some more.

My Solution: I'm just using background-geolocation to get and observable to get the current position of the device. With that given information I use the Haversine-Formula to calculate the distance between other coordinates. If the devices range falls below certain range to my geofence, i fire an event to inform the user. It's pretty quick and i have no restrictions in the capacity of geofences.

If https://github.com/cowbell/cordova-plugin-geofence/issues/243 is a good solution, let me know if it worked, so i can probably close this issue.

nilsk123 commented 6 years ago

Attached below is my xcode log. I Added the permission for always location services, overwrote the swift files to make it compile, looked at the SwiftData.swift fix / patch but as far as I can tell it's already included in my files.

You can see upon initializing the geofencing plugin it throws a swift data error xtracting tables. Eventhough it then said it initialized just fine, I suspect there is a problem with this. Do you guys see this in your logs? Can anyone post a fill SwiftData.swift thats working?

On initializing the controller I initialize the plugin and then add a geofence in the success callback. If this is successful, to confirm it worked, I log the result of .getWatched() which is always an empty array (you can see below as [])

`2017-12-19 09:46:33.269292+0100 GeofencingIosTryout[797:233508] GeofencePlugin - Plugin initialization SwiftData Error -> During: Finding Existing Tables -> Code: 403 - Error extracting table names from sqlite_master 2017-12-19 09:46:33.402417+0100 GeofencingIosTryout[797:233508] GeofencePlugin - Cannot fetch sqlite tables: Optional(403) 2017-12-19 09:46:33.402530+0100 GeofencingIosTryout[797:233508] GeofencePlugin - GeoNotificationManager init 2017-12-19 09:46:33.499483+0100 GeofencingIosTryout[797:233508] THREAD WARNING: ['GeofencePlugin'] took '263.886963' ms. Plugin should use a background thread. 2017-12-19 09:46:33.517771+0100 GeofencingIosTryout[797:233508] Geo init success. 2017-12-19 09:46:33.579102+0100 GeofencingIosTryout[797:233508] [] 2017-12-19 09:46:33.592475+0100 GeofencingIosTryout[797:233650] GeofencePlugin - GeoNotificationManager addOrUpdate

Main Thread Checker: UI API called on a background thread: -[UIApplication currentUserNotificationSettings] PID: 797, TID: 233650, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21 Backtrace: 4 GeofencingIosTryout 0x0000000100958c00 _T019GeofencingIosTryout22GeoNotificationManagerC17checkRequirementsSb_SaySSGAEtyF + 680 5 GeofencingIosTryout 0x0000000100957b30 _T019GeofencingIosTryout22GeoNotificationManagerC011addOrUpdatedE0yAA4JSONVF + 292 6 GeofencingIosTryout 0x0000000100953300 T019GeofencingIosTryout14GeofencePluginC11addOrUpdateySo20CDVInvokedUrlCommandCFyycfU + 608 7 GeofencingIosTryout 0x00000001009537b4 _T0Ix_IyB_TR + 48 8 libdispatch.dylib 0x00000001019212cc _dispatch_call_block_and_release + 24 9 libdispatch.dylib 0x000000010192128c _dispatch_client_callout + 16 10 libdispatch.dylib 0x000000010192d3dc _dispatch_queue_override_invoke + 984 11 libdispatch.dylib 0x00000001019329d0 _dispatch_root_queue_drain + 624 12 libdispatch.dylib 0x00000001019326f4 _dispatch_worker_thread3 + 136 13 libsystem_pthread.dylib 0x00000001823d706c _pthread_wqthread + 1268 14 libsystem_pthread.dylib 0x00000001823d6b6c start_wqthread + 4 2017-12-19 09:46:33.605973+0100 GeofencingIosTryout[797:233650] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication currentUserNotificationSettings] PID: 797, TID: 233650, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21 Backtrace: 4 GeofencingIosTryout 0x0000000100958c00 _T019GeofencingIosTryout22GeoNotificationManagerC17checkRequirementsSb_SaySSGAEtyF + 680 5 GeofencingIosTryout 0x0000000100957b30 _T019GeofencingIosTryout22GeoNotificationManagerC011addOrUpdatedE0yAA4JSONVF + 292 6 GeofencingIosTryout 0x0000000100953300 T019GeofencingIosTryout14GeofencePluginC11addOrUpdateySo20CDVInvokedUrlCommandCFyycfU + 608 7 GeofencingIosTryout 0x00000001009537b4 _T0Ix_IyB_TR + 48 8 libdispatch.dylib 0x00000001019212cc _dispatch_call_block_and_release + 24 9 libdispatch.dylib 0x000000010192128c _dispatch_client_callout + 16 10 libdispatch.dylib 0x000000010192d3dc _dispatch_queue_override_invoke + 984 11 libdispatch.dylib 0x00000001019329d0 _dispatch_root_queue_drain + 624 12 libdispatch.dylib 0x00000001019326f4 _dispatch_worker_thread3 + 136 13 libsystem_pthread.dylib 0x00000001823d706c _pthread_wqthread + 1268 14 libsystem_pthread.dylib 0x00000001823d6b6c start_wqthread + 4 2017-12-19 09:46:33.853159+0100 GeofencingIosTryout[797:233650] GeofencePlugin - AddOrUpdate geo: { "latitude" : 51.445376099999997, "transitionType" : 3, "notification" : { "id" : 10002340, "title" : "You crossed a fence", "openAppOnClick" : true, "text" : "You just arrived to Gliwice city center." }, "radius" : 3000, "id" : "69ca1b886fbe4e80a2344sd12312312312fsdfsdfsj", "longitude" : 5.4581122999999998 } 2017-12-19 09:46:33.906756+0100 GeofencingIosTryout[797:233508] GeofencePlugin - Starting monitoring for region CLCircularRegion (identifier:'69ca1b886fbe4e80a2344sd12312312312fsdfsdfsj', center:<+51.44537610,+5.45811230>, radius:3000.00m) lat 51.4453761 lng 5.4581123 of radius 3000.0 2017-12-19 09:46:33.936909+0100 GeofencingIosTryout[797:233508] Geofence added or updated 2017-12-19 09:46:33.969517+0100 GeofencingIosTryout[797:233508] []`

petvoj commented 6 years ago

I had the same problem. This repo https://github.com/dovk/geofence-fix helped me and now it is working. Thanks @dovk.