Open graphicgeek opened 6 years ago
@graphicgeek after some days trying to resolve this, i finally was able to compile the project and to prevent application crash after adding a new zone.
I was able to do that doing:
After all this, you should have files like the attached ones!
I didn't have the opportunity to test that notification really works, but geofence does all the passage (init and add/update) with no issues.
Hope this can help you.
Thanks @centos94, I will give this a try.
@graphicgeek let me know if it works so it can be useful for others with the same problem too!
Worked for me thanks !
Will this work using XCode9 or do we have to stay below that?
@dovk yes, it works with xcode 9!
@centos94 I went by your instructions as written above to @graphicgeek and it works on the Mac using XCode9 + no need for Swift code conversion anymore. Thank you very very much!
This worked for me. It looks like someone has forked the repo to create a version that has all of these files here https://github.com/compelling/cordova-plugin-geofence/
Note, I had to remove
Hopefully the fixed files will get merged into the main repo soon.
HI there
Not sure if it's related, but I'm not able to get it working on ios. I could build the project successfully using this fork (https://github.com/compelling/cordova-plugin-geofence/) and when I try to initialize the plugin, the success callback is called. I can also see the geofences watched by the geofence.getWatched() method, but the method onTransitionReceived is never called. When testing on android, it works fine.
Xcode Version 9.0.1 iOS: 11.0.3 Cordova iOS platform: 4.3.1 ionic v1 Project
Any ideas?
I realize now what worked was that I was able to complete the build without any errors, but the geofence itself still does not work. Can someone point me to a fork that works with Xcode 9 ?
@marcelomiura @dovk I'm not sure of that, and for now i have no way to test it, but i noticed that in the logs there is a warning Location always permissions not granted.
Now i tried to add in the plist file NSLocationAlwaysAndWhenInUseUsageDescription, the warning disappeared and the app asks me another authorization. Maybe is that.
Can you try it and tell us if it works? Although i don't know how to resolve, cause the logs says that the geofence are added correctly.
@centos94 I've already added NSLocationAlwaysAndWhenInUseUsageDescription on the plist too.
I could make it work simulating a big location change with Xcode. When disabling the location simulator, all my near geofences were detected at the same time.
But I'm not able to make this work testing a normal use case yet.
Firstly, thanks for the hard work on this. I am using Ionic Cloud build and I beleive they have upgraded it to use a new version of Xcode which does not use Swift 2.3. What are the plans to upgrade this plugin to use newer version of Swift? You can see my issues with Ionic 2 here: https://forum.ionicframework.com/t/ionic-package-ios-release-build-error-in-package-ionic-services/109507/15
Finally! Thank you again centos94 - I checked again and the solution works!
The .ipa was built on a macMini (OS Sierra 10.12.6) using XCode 9.0.1, and the screenshot of the geofence notification is from my iPhone (iOS 11.0.3).
In this build I also made the switch from UIWebView to WKWebView, and set the major packages to the latest versions, such as
I did not have to change much in the Xcode developer, other than adding the 1024 icon manually (until I figure that one out). And though I'm not sure I needed to, I ticked the location updates checkbox in Capabilities/Background modes. As far as permissons entries under Info, I didn't have to add anything, it seems easier to handle that in config.xml -
<platform name="ios">
<config-file parent="NSBluetoothPeripheralUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires bluetooth access to function properly</string>
</config-file>
<config-file parent="NSCalendarsUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires calendar access to function properly</string>
</config-file>
<config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires camera access to function properly</string>
</config-file>
<config-file parent="NSContactsUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires contacts access to function properly</string>
</config-file>
<config-file parent="NSLocationAlwaysAndWhenInUseUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} would like to check your location when app is active or in background</string>
</config-file>
<config-file parent="NSLocationAlwaysUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} would like to check your location when app is active or in background</string>
</config-file>
<config-file parent="NSLocationWhenInUseUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} would like to check your location when app is active or in background</string>
</config-file>
<config-file parent="NSMicrophoneUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires microphone access to function properly</string>
</config-file>
<config-file parent="NSMotionUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires motion detection access to function properly</string>
</config-file>
<config-file parent="NSPhotoLibraryUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} requires photo library access to function properly</string>
</config-file>
<config-file parent="NSRemindersUsageDescription" platform="ios" target="*-Info.plist">
<string>${EXECUTABLE_NAME} equires reminders access to function properly</string>
</config-file>
<feature name="CDVOrientation">
<param name="ios-package" value="CDVOrientation" />
</feature>
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<feature name="Console">
<param name="ios-package" value="CDVLogger" />
</feature>
<feature name="Device">
<param name="ios-package" value="CDVDevice" />
</feature>
<feature name="EmailComposer">
<param name="ios-package" value="APPEmailComposer" />
</feature>
<feature name="FacebookConnectPlugin">
<param name="ios-package" value="FacebookConnectPlugin" />
<param name="onload" value="true" />
</feature>
<feature name="GeofencePlugin">
<param name="ios-package" value="HWPGeofencePlugin" />
</feature>
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
<feature name="GestureHandler">
<param name="ios-package" value="CDVGestureHandler" />
<param name="onload" value="true" />
</feature>
<feature name="GooglePlus">
<param name="ios-package" value="GooglePlus" />
<param name="onload" value="true" />
</feature>
<feature name="HandleOpenUrl">
<param name="ios-package" value="CDVHandleOpenURL" />
<param name="onload" value="true" />
</feature>
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>
<feature name="IntentAndNavigationFilter">
<param name="ios-package" value="CDVIntentAndNavigationFilter" />
<param name="onload" value="true" />
</feature>
<feature name="Keyboard">
<param name="ios-package" onload="true" value="CDVKeyboard" />
</feature>
<feature name="Keyboard">
<param name="ios-package" onload="true" value="IonicKeyboard" />
</feature>
<feature name="LocalNotification">
<param name="ios-package" onload="true" value="APPLocalNotification" />
<param name="onload" value="false" />
</feature>
<feature name="LocalStorage">
<param name="ios-package" value="CDVLocalStorage" />
</feature>
<feature name="NativePageTransitions">
<param name="ios-package" value="NativePageTransitions" />
</feature>
<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>
<feature name="Sms">
<param name="ios-package" value="Sms" />
</feature>
<feature name="SplashScreen">
<param name="ios-package" value="CDVSplashScreen" />
<param name="onload" value="true" />
</feature>
<feature name="StatusBar">
<param name="ios-package" onload="false" value="CDVStatusBar" />
</feature>
There is one other thing that I did, I don't know if this is an issue with anyone else - I was getting too many permission error messages when the app initializes so I just remarked all the warnings.append in GeofencePlugin.swift.
By the way rodneyjoyce - Like many others I too was having a very difficult time with Ionic's unreliable Cloud Build. I finally gave up on them and got myself a macMini for the .ipa builds. It took a while to get used to but I now have a lot more control and understanding of the process now.
If this will help anyone, here are the relevant packeges I have in package.json
"@angular/animations": "4.4.4",
"@angular/cli": "1.4.4",
"@angular/common": "4.4.4",
"@angular/compiler": "4.4.4",
"@angular/compiler-cli": "4.4.4",
"@angular/core": "4.4.4",
"@angular/forms": "4.4.4",
"@angular/http": "4.4.4",
"@angular/platform-browser": "4.4.4",
"@angular/platform-browser-dynamic": "4.4.4",
"@angular/platform-server": "4.4.4",
"@angular/tsc-wrapped": "4.4.4",
"@ionic-native/app-minimize": "^4.3.3",
"@ionic-native/core": "^4.3.3",
"@ionic-native/device": "^4.3.3",
"@ionic-native/email-composer": "^4.3.3",
"@ionic-native/facebook": "^4.3.3",
"@ionic-native/geofence": "^4.3.3",
"@ionic-native/geolocation": "^4.3.3",
"@ionic-native/google-plus": "^4.3.3",
"@ionic-native/in-app-browser": "^4.3.3",
"@ionic-native/keyboard": "^4.3.3",
"@ionic-native/local-notifications": "^4.3.3",
"@ionic-native/native-page-transitions": "^4.3.3",
"@ionic-native/network": "^4.3.3",
"@ionic-native/screen-orientation": "^4.3.3",
"@ionic-native/sms": "^4.3.3",
"@ionic-native/splash-screen": "^4.3.3",
"@ionic-native/status-bar": "^4.3.3",
"angularfire2": "4.0.0-rc.1",
"autoprefixer": "^7.1.6",
"com.telerik.plugins.nativepagetransitions": "^0.6.5",
"cordova-android": "6.3.0",
"cordova-android-play-services-gradle-release": "0.0.2",
"cordova-android-support-gradle-release": "0.0.2",
"cordova-ios": "^4.5.3",
"cordova-plugin-add-swift-support": "^1.7.0",
"cordova-plugin-app-event": "^1.2.1",
"cordova-plugin-appminimize": "^1.0.0",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-console": "^1.1.0",
"cordova-plugin-device": "^1.1.6",
"cordova-plugin-email-composer": "^0.8.11",
"cordova-plugin-facebook4": "^1.9.1",
"cordova-plugin-geofence": "^0.7.0",
"cordova-plugin-geolocation": "^2.4.3",
"cordova-plugin-googleplus": "^5.1.1",
"cordova-plugin-inappbrowser": "^1.7.1",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-keyboard": "^1.1.5",
"cordova-plugin-network-information": "^1.3.3",
"cordova-plugin-screen-orientation": "^2.0.1",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.3",
"cordova-plugin-whitelist": "^1.3.2",
"cordova-sms-plugin": "^0.1.11",
"de.appplant.cordova.plugin.local-notification": "^0.8.5",
"es6-promise-plugin": "^4.1.1",
"firebase": "4.4.0",
"ionic-angular": "^3.8.0",
"ionic-plugin-keyboard": "^2.2.1",
"promise-polyfill": "^6.0.2",
"rxjs": "5.4.3",
"sw-toolbox": "^3.6.0",
"zone.js": "0.8.18",
"@ionic/app-scripts": "^3.0.0",
"typescript": "2.3.4"
BTW I read a pretty good explanation about the Location permission here https://mackuba.eu/2017/07/13/changes-to-location-tracking-in-ios-11/
Hi, do you plan a date for release compatibility with swift 3 ?
I noticed that Swift 4.0 is the default version in Xcode 9.1, I understand you can still use Swift 3.0 code, but the compatibility issue might be relevant as well.
Or maybe a date for Swift4 ? ;)
@centos94 , I am able to compile code by changing 3 swifts files, but geofence is still not working in IOS device (however fence is adding perfectly but unable to trigger transition), any Idea what I am missing?
Hello @brijesh-p, did you try what @dovk has done? He said that with those steps he was able to made it works.
Sorry, I forgot to mention that, although I might have been able to do this differently, I copy the 3 sources to 3 different places -
<_path_to_project_>/<_project_name_>/node_modules/cordova-plugin-geofence/src/ios <_path_to_project_>/<_project_name_>/plugins/cordova-plugin-geofence/src/ios <_path_to_project_>/<_project_name_>/platforms/ios/<_project_name_>/Plugins/cordova-plugin-geofence
And as I wrote earlier, at one point it wasn't working because I had a spelling mistake in one of the fence json parameters (openAppOnClic instead of openAppOnClick).
Also - as a result of different behavior between Android and iOS, and based on suggestions that I read about, I define the fence json parameters as follows (although some may seem obvious or may not be necessary) -
If I notice anything else I did, I'll add it here later - Good luck !
@dovk, thanks. Its is possible to share, .swifts files for IOS?, meantime I am looking your suggestions.
@brijesh-p I'm still facing the same issue as you. Geofences added, but transitions not triggered on ios. Have you made any progress? I saw suggestions from @dovk, but a radius of 300 is too much for my application. (But even setting to more than 300 on my case, it did not work).
I've already gone down to radius of 100 and it's ok, so I guess that was never a real problem there.
I placed some of the relevant code here https://github.com/dovk/geofence-fix I'm sorry if it's hard to follow, it's overloaded with specific app business logic. l_fence.ts is where we initialize and set the fence, and s_privateApp.ts is where we invoke those functions. But you can get an idea of how we defined the fence parameters and so on, and might see something that could help you.
You might also notice things in package.json or config.xml that would be beneficial to add.
Regarding the Swift sources - I took those from https://github.com/ypelud/cordova-plugin-geofence In GeofencePlugin.swift I remarked out all the errors.append and warnings append because they were always popping up prematurely when the app came up - I believe it's something I need to fix like checking for platform.ready() earlier than I do.
And in the build_ios.sh (I know it's ugly - it's the first shell script I ever wrote) you can see how I automatically run the build and copy the Swift files to their respective places.
Take a look and let me know.
@dovk , thanks. I am looking https://github.com/dovk/geofence-fix, pls confirm if geofcence worked on IOS on this code? with .swift files (https://github.com/ypelud/cordova-plugin-geofence)
Yes, absolutely, as you can see in the screenshot above from my iPhone. And as I wrote, it is all with recent versions, including using the new WKWebView, node/npm, and cordova, whose latest versions had caused problems and forced me in the past to revert to previous versions - now everything is up-to-date. By the way, it did not go well with XCode 9.1.0, so I stayed at 9.0.1.
The .ipa was built on a macMini (OS Sierra 10.12.6) using XCode 9.0.1, and the screenshot of the geofence notification is from my iPhone (iOS 11.0.3). In this build I also made the switch from UIWebView to WKWebView, and set the major packages to the latest versions, such as ionic: 3.16.0 cordova: 7.1.0 cordova-ios: 4.5.3 ionic-angular: 3.8.0 node: 8.9.0 npm: 5.5.1
I also found it important to make sure that everyting regarding notifications is also defined and installed correctly, because at one point the problem wasn't with Geofence but rather with localNotifications. For example using all those permission definitions in config.xml (under config-file)
Hi, guys, this thread is very hard to follow. I understand that the compatibility with Swift >=3 is not already working, but a temporary patch exists. Thats true ?
In this case is it possible to describe the full procedure (with version required of ios) to follow to use geofence plugin ?
Thanks in advance.
Please you can define your current problem, because there are a lot of possibilities. Try to include relevant sources.
My initial problem was : "I had trouble following the procedure to make geofence work on the latest Xcode versions". But I tried to understand your explanations well now i can pass the compilation step.
I will try to explain what I did and the new problem that I am experiencing now.
Try to code as close as possible to my code here https://github.com/dovk/geofence-fix and go over thw efine points I wrote there and above here, Using the Swift code from https://github.com/ypelud/cordova-plugin-geofence is a prequisite of course but the TS script also needs to be handled in a certain way.
I am also facing the same issue and the above mentioned solution is not working for me
If you put some of your code up I can take a look. It still works for us but be aware that it might not be a viable solution for your purposes in any case since there are limitations when using the plugin in a Web/Javascript-based app framework like Ionic - geolocation and geofence works fine when the app is active in foreground, or when the app is minimized (for example when focusing on another app or pressing the back button on Android). However, when the app is closed, for example when you close the app window from the app list on Android, or swipe the app up on iOS, only the notification will work, not the actual Javascript code that you want to run when the entering or leaving event occurs. I am checking different solutions for that case.
Thank you for your response. I am working on Ionic platform and in Android the geofence is working fine without having any issue. In iOS it is added succesfully(as per the log) but no notification is showing.
{code} import { Component } from '@angular/core'; import { NavController, Platform } from 'ionic-angular'; import { Geofence } from '@ionic-native/geofence'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; import { Headers, RequestOptions, ResponseContentType } from '@angular/http'; import {Observable} from 'rxjs/Observable'; import { Storage } from '@ionic/storage';
@Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage {
constructor(public navCtrl: NavController, private geofence: Geofence, public http: Http, private plt: Platform, private file: File, private fileOpener: FileOpener) { // initialize the plugin
}
callGeofence(){ this.geofence.initialize().then( // resolved promise does not return a value () => { console.log('Geofence Plugin Ready'); this.addGeofence(); }, (err) => console.log(err) ) }
private addGeofence() { //options describing geofence let fence = { id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', //any unique ID latitude: 8.54748, //center of geofence radius longitude: 76.87932, radius: 100, //radius to edge of geofence in meters transitionType: 3, //see 'Transition Types' below notification: { //notification settings id: 1, //any unique ID title: 'You crossed a fence', //notification title text: 'You just arrived to Gliwice city center.', //notification body openAppOnClick: true //open app when notification is tapped } } this.geofence.addOrUpdate(fence).then( () => console.log('Geofence added'), (err) => console.log('Geofence failed to add') ); }
}
{code}
We learnt alot in the process of trying to integrate the Geofence plugin in our app, but finally removed it from our app today and replaced it with simple home-made Geofence functionality based on the Background Geolocation plugin. In our case the Geofence plugin eventually worked, but it seems to run your triggered Javascript code only when the app is in active or minimized mode, not when the app is closed - and in our case we must have Geofence monitoring when the app is closed as well. And while it appears that the Background Geolocation plugin doesn't run Javascript code in background mode either, it does record all location tracking information while in background mode. We can then retrieve this information when the app is alive again with the getLocations() function. And just as important - the Background Geolocation plugin records foreground geolocation as well - so for the purpose of geolocation tracking, all you need is the Background Geolocation plugin. You may perhaps need the regular Geolocation plugin if, as in our case, you need to know at a specific moment your location coordinates - but remember this will only work in foreground mode when the app is active. After that we added our own Geofence-like solution by using the haversine algorithm to calculate the distance of the recorded coordinates in relation to the target location. Thanks to Josh Morony's tutorial we were able to do this in a day or two, and I hope it will serve our app well. Regarding your question, I wrote earlier that we made some adjustments to accomodate for differences that we found between iOS and Android before passing the fence object to the addOrUpdate() function -
if (ios) {
this.smallIcon = '/icon'
this.icon = '/assets/img/icon.png'
this.latitude = parseFloat(parms.latitude)
this.longitude = parseFloat(parms.longitude)
}else{
this.smallIcon = 'res://icon'
this.icon = 'file://assets/img/icon.png'
this.latitude = (parms.latitude)
this.longitude = (parms.longitude)
}
and the fence object is defined as
{
id: parms.idIn,
latitude: this.latitude,
longitude: this.longitude,
radius: this.radius,
transitionType: 1,
notification: {
text: text,
openAppOnClick: false,
autoClear: true,
smallIcon: this.smallIcon,
icon: this.icon}
}
I also mentioned above that:
I've seen some other closed issues that indicated this has been fixed but it is not building for me with a fresh HelloWorld app.
Cordova 7.0.1 ios platform 4.4.0 (also tried with 4.5.0) Xcode 8.3.3 (I also just updated to 9.0 with the same results) cordova-plugin-geofence 0.7.0
I even tried updating cordova-plugin-add-swift-support to version 1.7.0 but no luck.
Here's the log output: