Skip to content

Commit

Permalink
feat(ios): Support iOS 10 beta
Browse files Browse the repository at this point in the history
Starting with iOS 10, the `NSCameraUsageDescription` string is required to avoid a runtime exit when the camera is used. This commit adds support to the tests, a configuration update to the swift-support.js hook, and some documentation
  • Loading branch information
bitjson committed Aug 15, 2016
1 parent cf69cd1 commit fa7ef5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,27 @@ function displayContents(err, text){

This plugin requires some additional installation steps for the iOS platform.

The iOS component of the plugin is written in Swift 2. To enable it, be sure you're running the lastest version of Xcode, then add the following hook to the iOS platform in your Cordova app's `config.xml`:
The iOS component of the plugin is written in Swift 2.3. To enable it, be sure you're running the lastest version of Xcode, then add the following hook and setting to the iOS platform in your Cordova app's `config.xml`:

```xml
<platform name="ios">
<hook type="before_build" src="plugins/cordova-plugin-qrscanner/scripts/swift-support.js" />
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>The camera is used to read QR codes.</string>
</config-file>
</platform>
```

This script requires the `xcode` npm module:
The script requires the `xcode` npm module:

```bash
npm install --save xcode
```

Swift will now be enabled during your build, and the `QRScanner` plugin will be available in your app.

Starting with iOS 10, the `NSCameraUsageDescription` string is also required to avoid a runtime exit. This field can be provided in a single language, localized using the `InfoPlist.strings` file, or simply left empty (`<string></string>`).

#### Using multiple Cordova plugins written in Swift

Because Cordova is written in Objective-C, Cordova plugins written in Swift [require a `bridging header` to interact with Cordova](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html).
Expand Down
2 changes: 2 additions & 0 deletions scripts/swift-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var
xcode = require('xcode'),

BUILD_VERSION = '7.0',
SWIFT_VERSION_XCODE = '2.3',
BUILD_VERSION_XCODE = '"' + BUILD_VERSION + '"',
RUNPATH_SEARCH_PATHS = '@executable_path/Frameworks',
RUNPATH_SEARCH_PATHS_XCODE = '"' + RUNPATH_SEARCH_PATHS + '"',
Expand Down Expand Up @@ -132,6 +133,7 @@ module.exports = function (context) {
buildSettings.SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeadXcode;
buildSettings.IPHONEOS_DEPLOYMENT_TARGET = BUILD_VERSION_XCODE;
buildSettings.ENABLE_BITCODE = ENABLE_BITCODE_XCODE;
buildSettings.SWIFT_VERSION = SWIFT_VERSION_XCODE;
});

// Writing the file again
Expand Down
3 changes: 3 additions & 0 deletions tests/project/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<preference name="orientation" value="all" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>The test app uses the camera to read QR codes.</string>
</config-file>
</platform>
<plugin name="cordova-plugin-qrscanner" spec="../../cordova-plugin-qrscanner" />
<plugin name="cordova-plugin-qrscanner-tests" spec="../../cordova-plugin-qrscanner/tests" />
Expand Down

0 comments on commit fa7ef5b

Please sign in to comment.