Troubleshooting Ionic Native Geofence Plugin Build Issues

Troubleshooting Ionic Native Geofence Plugin Build Issues

[[email protected], [email protected]]

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:

  1. Start a new ionic (as of 3.7.1) app ionic start geofence-app blank
  2. Change the directory to your new app cd geofence-app
  3. Add the geofence cordova plugin ionic cordova plugin add cordova-plugin-geofence
  4. Add the npm module npm install --save @ionic-native/geofence
  5. Do not add the preference tag for 'UseLegacySwiftLanguageVersion'
  6. Open your project folder in a text editor as we now need to update 3 files in the geofence plugin folder.
  7. 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
  8. Edit your config.xml to update the project package id <widget id="com.companyname.geofence-app" ...
  9. Add the ios platform to cordova cordova platform add ios this will rebuild the plugins directory
  10. Open your project in xcode /geofence-app/platforms/ios/MyApp.xcodeproj and add a development team to the signing section under general settings
  11. Build your app ionic cordova build ios. You should now be error free.

For an existing app:

  1. Remove <preference name="UseLegacySwiftLanguageVersion" value="true" /> from your config.xml if it exists.
  2. Follow step 7 above.
  3. Remove the ios platform from cordova cordova platform rm ios
  4. Add the ios platform cordova platform add ios
  5. Follow steps 10 & 11 above.
Show Comments