The latest version of xcode (9.0) comes with support for Swift version 3 and 4. Legacy versions of swift just ain't gonna work. So if you are going to build an app that uses the Geofence plugin, then you are going to run into build issues when you try to run
ionic cordova build ios command for example. This is because the version of the plugin currently available at npm uses Swift 2 syntax. But there is a solution and it can be found in the plugins repo.
Follow the steps below for a new app:
- Start a new ionic (as of 3.7.1) app
ionic start geofence-app blank
- Change the directory to your new app
- Add the geofence cordova plugin
ionic cordova plugin add cordova-plugin-geofence
- Add the npm module
npm install --save @ionic-native/geofence
- Do not add the preference tag for 'UseLegacySwiftLanguageVersion'
- Open your project folder in a text editor as we now need to update 3 files in the geofence plugin folder.
- Navigate to /plugins/cordova-plugin-geofence/src/ios, here you will find 3 swift files that we need to replace with the content from the following links. GeofencePlugin.swift, SwiftData.swift, SwiftyJson.swift
- Edit your config.xml to update the project package id
<widget id="com.companyname.geofence-app" ...
- Add the ios platform to cordova
cordova platform add iosthis will rebuild the plugins directory
- Open your project in xcode /geofence-app/platforms/ios/MyApp.xcodeproj and add a development team to the signing section under general settings
- Build your app
ionic cordova build ios. You should now be error free.
For an existing app:
<preference name="UseLegacySwiftLanguageVersion" value="true" />from your config.xml if it exists.
- Follow step 7 above.
- Remove the ios platform from cordova
cordova platform rm ios
- Add the ios platform
cordova platform add ios
- Follow steps 10 & 11 above.
Subscribe to Invisibleloop
Get the latest posts delivered right to your inbox