Skip to content

Commit

Permalink
Merge pull request #38 from bitjson/feature/swift-support-via-dependency
Browse files Browse the repository at this point in the history
Update iOS implementation to Swift 3
  • Loading branch information
bitjson authored Oct 6, 2016
2 parents 29e5bbf + 74a4d0e commit 53bec9f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 303 deletions.
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-qrscanner"
version="2.2.0">
version="2.3.4">

<name>QRScanner</name>

Expand Down Expand Up @@ -35,7 +35,7 @@
<param name="ios-package" value="QRScanner"/>
</feature>
</config-file>
<header-file src="src/ios/QRScanner-Bridging-Header.h" />
<dependency id="cordova-plugin-swift-support" spec="~3.1.0" />
<source-file src="src/ios/QRScanner.swift"/>
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>The camera is used to scan QR codes.</string>
Expand Down
48 changes: 1 addition & 47 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ QRScanner's native camera preview is rendered behind the Cordova app's webview,
cordova plugin add cordova-plugin-qrscanner
```

On most platforms, simply adding the plugin to the Cordova project will make the `window.QRScanner` global object available once the `deviceready` event propagates.
Simply adding this plugin to the Cordova project will make the `window.QRScanner` global object available once the `deviceready` event propagates.

### Usage

Expand Down Expand Up @@ -79,52 +79,6 @@ QRScanner.show();

Please see the [full API docs](#api) for details about each method, [error handling](#error-handling), and [platform specific details](#platform-specific-details).

### iOS Installation

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

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 scan QR codes.</string>
</config-file>
</platform>
```

The script requires the `xcode` npm module. (This will already be installed as a dependency of `cordova-plugin-qrscanner` if you install this package via npm.)

```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, a non-empty `NSCameraUsageDescription` string is also required to avoid a runtime exit. This field can be provided in a single language or localized using the `InfoPlist.strings` file. (Note: Apps with an empty `NSCameraUsageDescription` will not exit at runtime, but are rejected by iTunes Connect when uploaded for distribution.)

#### 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).

A project can only have one bridging header. If your app uses plugins other than `cordova-plugin-qrscanner` which are also written in Swift, you will need to create a master bridging header to import each. Create a new bridging header and import each of the plugins' bridging headers, for example:

```c
// MyProject-Bridging-Header.h
// Use this file to import your target's public headers that you would like to expose to Swift.

//cordova-plugin-apple-watch
#import "Watch-Bridge.h"

//com.eface2face.iosrtc
#import "iosrtc-Bridging-Header.h"

//cordova-plugin-qrscanner
#import "QRScanner-Bridging-Header.h"
```
Copy the script from `cordova-plugin-qrscanner/scripts/swift-support.js` into your project (eg. into the `hooks` folder), and modify the `BRIDGING_HEADER_END` variable to point to your new bridging header. Finally, remove and re-add the ios platform to trigger the hook. See [this issue](https://github.com/eface2face/cordova-plugin-iosrtc/issues/9) for more information.

### Electron or NW.js usage without `cordova-browser`

If your app uses the Cordova Browser platform, simply adding the plugin to the Cordova project will make the `window.QRScanner` global object available once the `deviceready` event propagates. For apps not using `cordova-browser`, this plugin is also available as a simple javascript library.
Expand Down
143 changes: 0 additions & 143 deletions scripts/swift-support.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/ios/QRScanner-Bridging-Header.h

This file was deleted.

Loading

0 comments on commit 53bec9f

Please sign in to comment.