├── .DS_Store ├── Images └── nRF8001-Swift_rounded.jpg ├── LICENSE ├── README.md ├── nRF8001-Swift.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── developer.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── Michael.xcuserdatad │ └── xcschemes │ │ ├── nRF8001-Swift.xcscheme │ │ └── xcschememanagement.plist │ └── developer.xcuserdatad │ └── xcschemes │ ├── nRF8001-Swift.xcscheme │ └── xcschememanagement.plist └── nRF8001-Swift ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── NRFManager.swift └── ViewController.swift /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichMich/nRF8001-Swift/4231966aa13f5440f8fd379eaf51875b0ef0c643/.DS_Store -------------------------------------------------------------------------------- /Images/nRF8001-Swift_rounded.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichMich/nRF8001-Swift/4231966aa13f5440f8fd379eaf51875b0ef0c643/Images/nRF8001-Swift_rounded.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![Xcode Tested](http://img.shields.io/badge/Xcode%20Tested-Xcode%207.1.1-orange.svg?style=flat) 3 | 4 | ![Bluefruit LE nRF8001 Breakout](https://raw.githubusercontent.com/MichMich/nRF8001-Swift/master/Images/nRF8001-Swift_rounded.jpg) 5 | 6 | nRF8001-Swift 7 | ============= 8 | 9 | **nRF8001-Swift** was written by **[Michael Teeuw](http://michaelTeeuw.nl)** [[twitter](https://twitter.com/michmich)]. 10 | 11 | 12 | 13 | - [What is it?](#what-is-it) 14 | - [How to use](#how-to-use) 15 | - [Initialization](#initialization) 16 | - [Initialization examples:](#initialization-examples) 17 | - [Properties](#properties) 18 | - [Instance methods](#instance-methods) 19 | - [Delegate methods](#delegate-methods) 20 | - [Delegates AND Closures?!](#delegates-and-closures!) 21 | - [TL;DR - Give me the most simple example!](#tldr---give-me-the-most-simple-example!) 22 | - [Yeah, cool! But how do I connect my Bluefruit Breakout Board?](#yeah-cool!-but-how-do-i-connect-my-bluefruit-breakout-board) 23 | - [Disclaimer](#disclaimer) 24 | - [Contributing](#contributing) 25 | 26 | 27 | 28 | # What is it? 29 | While working on one of my Arduino projects, I was in the need for a simple wrapper for communication with the [Adafruit Bluefruit LE nRF8001 Breakout](https://www.adafruit.com/products/1697). 30 | 31 | Since I was unable to find one (especially one that was Swift-ready) I wrote a Swift-wrapper myself. It is based on a [Bluefruit LE Connect](https://github.com/adafruit/Bluefruit_LE_Connect). 32 | 33 | It has all the basic needs for basic two way communication and is easy to implement. 34 | 35 | # How to use 36 | Add the [NRFManager.swift](https://github.com/MichMich/nRF8001-Swift/blob/master/nRF8001-Swift/NRFManager.swift) file to your project and use the following implementation: 37 | 38 | ##Initialization 39 | 40 | Use the shared instance: 41 | 42 | ```Swift 43 | let nrfManager = NRFManager.sharedInstance 44 | ``` 45 | 46 | Or simply create an instance yourself: 47 | 48 | ```Swift 49 | let nrfManager = NRFManager() 50 | ``` 51 | 52 | The Initializer takes 5 arguments. All of these arguments are optional and can be nil: 53 | 54 | ```Swift 55 | let nrfManager = NRFManager(delegate:NRFManagerDelegate? = nil, onConnect connectionCallback:(()->())? = nil, onDisconnect disconnectionCallback:(()->())? = nil, onData dataCallback:((data:NSData?, string:String?)->())? = nil, autoConnect:Bool = true) 56 | ``` 57 | 58 | - The **delegate** argument sets the delegate for the NRFManager instance. The delegate must conform to the `NRFManagerDelegate`. Default is `nil`. 59 | 60 | - The **onConnect** argument can take a closure to execute when the NRFManager connects to the nRF8001 module. Default is `nil`. 61 | 62 | - The **onDisconnect** argument can take a closure to execute when the NRFManager disconnects from the nRF8001 module. Default is `nil`. 63 | 64 | - The **onData** argument can take a closure to execute when the NRFManager receives data from the nRF8001 module. This closure will receive a `data:NSData?` and `string:String?` object. Default is `nil`. 65 | 66 | - The **autoConnect** argument will tell the manager if it has to start searching and connect right away, and if it has to reconnect when the connection is lost. Default is `true`. 67 | 68 | ###Initialization examples: 69 | 70 | ```Swift 71 | // basic object which won't connect 72 | let nrfBasicExample = NRFManager(autoConnect:false) 73 | 74 | // using delegates 75 | let nrfDelegateExample = NRFManager(delegate:self) 76 | 77 | // using closures 78 | let nrfClosureExample = NRFManager( 79 | onConnect: { 80 | println("Connected") 81 | }, 82 | onDisconnect: { 83 | println("Disconnected") 84 | }, 85 | onData: { 86 | (data:NSData?, string:String?)->() in 87 | println("Recieved data - String: \(string) - Data: \(data)") 88 | } 89 | ) 90 | ``` 91 | 92 | ###Properties 93 | After initialization, it's possible to (re)set the following properties: 94 | 95 | - `nrfManager.delegate` to set the delegate. 96 | 97 | - `nrfManager.connectionCallback` to set the onConnect callback. 98 | 99 | - `nrfManager.disconnectionCallback` to set the onDisconnect callback. 100 | 101 | - `nrfManager.dataCallback` to set the onData callback. 102 | 103 | - `nrfManager.autoConnect` to set the auto (re)connection behaviour. 104 | 105 | - `nrfManager.verbose` to enable or disable logging. This might be helpfull during debugging. 106 | 107 | Additionally, the following properties are read-only: 108 | 109 | - `nrfManager.connectionMode` returns an enum: *ConnectionStatus* (*.Disconnected*, *.Scanning*, *.Connected*). 110 | 111 | - `nrfManager.connectionStatus` returns an enum: *ConnectionMode* (*.None*, *.PinIO*, *.UART*). 112 | 113 | ## Instance methods 114 | A NRFManager can receive the following method calls: 115 | 116 | ```Swift 117 | nrfManager.connect() 118 | ``` 119 | Start looking for a connection. Only necessary when `autoConnect` is set to `false`. 120 | 121 | ```Swift 122 | nrfManager.disconnect() 123 | ``` 124 | Disconnect from the nRF8001 device. Note that when `autoConnect` is set to `true`, the NRFManager will be an annoying prick and start looking for an new connection instantly ... 125 | 126 | ```Swift 127 | nrfManager.writeString(string:String) -> Bool 128 | ``` 129 | Send a String to the nRF8001 device. It will return a Bool to tell you if it was possible to send it. (If there is no current connection, this will return `false` in all other cases this will return `true`.) 130 | 131 | ```Swift 132 | nrfManager.writeData(data:NSData) -> Bool 133 | ``` 134 | Send raw data (NSData) to the nRF8001 device. It will return a Bool to tell you if it was possible to send it. (If there is no current connection, this will return `false` in all other cases this will return `true`.) 135 | 136 | ## Delegate methods 137 | The following methods are part of the NRFManagerDelegate protocol: 138 | 139 | ```Swift 140 | nrfDidConnect(nrfManager:NRFManager) 141 | ``` 142 | Called when the NRFManager connects to the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which connected. 143 | 144 | ```Swift 145 | nrfDidDisconnect(nrfManager:NRFManager) 146 | ``` 147 | Called when the NRFManager disconnect from the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which disconnected. 148 | 149 | ```Swift 150 | nrfReceivedData(nrfManager:NRFManager, data:NSData?, string:String?) 151 | ``` 152 | Called when the NRFManager receives data from the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which received data. `data` will contain the raw data, `string` will contain the string representation of the received data. 153 | 154 | # Delegates AND Closures?! 155 | The reason I implemented both is because I was unable to decide what the best approach is. Personally I tend to prefer the delegate route. 156 | 157 | Although it is possible to both use the closures and the delegates, it wouldn't be the best idea to do so. That being said: Feel free to go wild! ... Both the delegate method and closure will be called when appropriate. 158 | 159 | All closures and delegate methods are optional. 160 | 161 | # TL;DR - Give me the most simple example! 162 | Okay okay, you lazy ass ... Here you go! 163 | 164 | Using closures: 165 | 166 | ```Swift 167 | class ViewController: UIViewController { 168 | 169 | var nrfManager:NRFManager! 170 | 171 | override func viewDidLoad() 172 | { 173 | super.viewDidLoad() 174 | 175 | nrfManager = NRFManager( 176 | onConnect: { 177 | println("Connected") 178 | self.sendData() 179 | }, 180 | onDisconnect: { 181 | println("Disconnected") 182 | }, 183 | onData: { 184 | (data:NSData?, string:String?)->() in 185 | println("Received data - String: \(string) - Data: \(data)") 186 | } 187 | ) 188 | } 189 | 190 | func sendData() 191 | { 192 | let result = self.nrfManager.writeString("Hello, world!") 193 | } 194 | } 195 | ``` 196 | Using delegates: 197 | 198 | ```Swift 199 | class ViewController: UIViewController, NRFManagerDelegate { 200 | 201 | var nrfManager:NRFManager! 202 | 203 | override func viewDidLoad() 204 | { 205 | super.viewDidLoad() 206 | nrfManager = NRFManager(delegate:self) 207 | } 208 | 209 | func sendData() 210 | { 211 | let result = self.nrfManager.writeString("Hello, world!") 212 | } 213 | 214 | // NRFManagerDelegate methods 215 | 216 | func nrfDidConnect(nrfManager:NRFManager) 217 | { 218 | println("Connected") 219 | self.sendData() 220 | } 221 | 222 | func nrfDidDisconnect(nrfManager:NRFManager) 223 | { 224 | println("Disconnected") 225 | } 226 | 227 | func nrfReceivedData(nrfManager:NRFManager, data: NSData?, string: String?) { 228 | println("Received data - String: \(string) - Data: \(data)") 229 | } 230 | } 231 | ``` 232 | 233 | You can check out the example project to see how it works. It includes both the delegate and closure usage. 234 | 235 | # Yeah, cool! But how do I connect my Bluefruit Breakout Board? 236 | 237 | Check Adafruit's [awesome tutorial](https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout) on how to use the Bluefruit Breakout Board. You can use the echo example sketch to test out nRF8001-Swift. 238 | 239 | # Disclaimer 240 | 241 | This is my fist bluetooth experiment. So be gentle. ;) 242 | 243 | # Contributing 244 | 245 | Forks, pull requests and other feedback are welcome. 246 | 247 | 248 | --- 249 | 250 | *Photos Courtesy of [Adafruit](https://www.adafruit.com/products/1697).* 251 | -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4CACBDF61C0B6F6D006A9937 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACBDF51C0B6F6D006A9937 /* AppDelegate.swift */; }; 11 | 4CACBDF81C0B6F6D006A9937 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACBDF71C0B6F6D006A9937 /* ViewController.swift */; }; 12 | 4CACBDFB1C0B6F6D006A9937 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CACBDF91C0B6F6D006A9937 /* Main.storyboard */; }; 13 | 4CACBDFD1C0B6F6D006A9937 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CACBDFC1C0B6F6D006A9937 /* Assets.xcassets */; }; 14 | 4CACBE001C0B6F6D006A9937 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CACBDFE1C0B6F6D006A9937 /* LaunchScreen.storyboard */; }; 15 | 4CACBE081C0B6F7D006A9937 /* NRFManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACBE071C0B6F7D006A9937 /* NRFManager.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 4CACBDF21C0B6F6D006A9937 /* nRF8001-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "nRF8001-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 4CACBDF51C0B6F6D006A9937 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 4CACBDF71C0B6F6D006A9937 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 4CACBDFA1C0B6F6D006A9937 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 4CACBDFC1C0B6F6D006A9937 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 4CACBDFF1C0B6F6D006A9937 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | 4CACBE011C0B6F6D006A9937 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 4CACBE071C0B6F7D006A9937 /* NRFManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NRFManager.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 4CACBDEF1C0B6F6D006A9937 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 4CACBDE91C0B6F6D006A9937 = { 41 | isa = PBXGroup; 42 | children = ( 43 | 4CACBDF41C0B6F6D006A9937 /* nRF8001-Swift */, 44 | 4CACBDF31C0B6F6D006A9937 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 4CACBDF31C0B6F6D006A9937 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 4CACBDF21C0B6F6D006A9937 /* nRF8001-Swift.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 4CACBDF41C0B6F6D006A9937 /* nRF8001-Swift */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 4CACBE071C0B6F7D006A9937 /* NRFManager.swift */, 60 | 4CACBDF51C0B6F6D006A9937 /* AppDelegate.swift */, 61 | 4CACBDF71C0B6F6D006A9937 /* ViewController.swift */, 62 | 4CACBDF91C0B6F6D006A9937 /* Main.storyboard */, 63 | 4CACBDFC1C0B6F6D006A9937 /* Assets.xcassets */, 64 | 4CACBDFE1C0B6F6D006A9937 /* LaunchScreen.storyboard */, 65 | 4CACBE011C0B6F6D006A9937 /* Info.plist */, 66 | ); 67 | path = "nRF8001-Swift"; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 4CACBDF11C0B6F6D006A9937 /* nRF8001-Swift */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 4CACBE041C0B6F6D006A9937 /* Build configuration list for PBXNativeTarget "nRF8001-Swift" */; 76 | buildPhases = ( 77 | 4CACBDEE1C0B6F6D006A9937 /* Sources */, 78 | 4CACBDEF1C0B6F6D006A9937 /* Frameworks */, 79 | 4CACBDF01C0B6F6D006A9937 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = "nRF8001-Swift"; 86 | productName = "nRF8001-Swift"; 87 | productReference = 4CACBDF21C0B6F6D006A9937 /* nRF8001-Swift.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 4CACBDEA1C0B6F6D006A9937 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0710; 97 | LastUpgradeCheck = 0800; 98 | ORGANIZATIONNAME = "Michael Teeuw"; 99 | TargetAttributes = { 100 | 4CACBDF11C0B6F6D006A9937 = { 101 | CreatedOnToolsVersion = 7.1.1; 102 | DevelopmentTeam = 54JDK55DR5; 103 | LastSwiftMigration = 0800; 104 | }; 105 | }; 106 | }; 107 | buildConfigurationList = 4CACBDED1C0B6F6D006A9937 /* Build configuration list for PBXProject "nRF8001-Swift" */; 108 | compatibilityVersion = "Xcode 3.2"; 109 | developmentRegion = English; 110 | hasScannedForEncodings = 0; 111 | knownRegions = ( 112 | en, 113 | Base, 114 | ); 115 | mainGroup = 4CACBDE91C0B6F6D006A9937; 116 | productRefGroup = 4CACBDF31C0B6F6D006A9937 /* Products */; 117 | projectDirPath = ""; 118 | projectRoot = ""; 119 | targets = ( 120 | 4CACBDF11C0B6F6D006A9937 /* nRF8001-Swift */, 121 | ); 122 | }; 123 | /* End PBXProject section */ 124 | 125 | /* Begin PBXResourcesBuildPhase section */ 126 | 4CACBDF01C0B6F6D006A9937 /* Resources */ = { 127 | isa = PBXResourcesBuildPhase; 128 | buildActionMask = 2147483647; 129 | files = ( 130 | 4CACBE001C0B6F6D006A9937 /* LaunchScreen.storyboard in Resources */, 131 | 4CACBDFD1C0B6F6D006A9937 /* Assets.xcassets in Resources */, 132 | 4CACBDFB1C0B6F6D006A9937 /* Main.storyboard in Resources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXResourcesBuildPhase section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | 4CACBDEE1C0B6F6D006A9937 /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | 4CACBDF81C0B6F6D006A9937 /* ViewController.swift in Sources */, 144 | 4CACBE081C0B6F7D006A9937 /* NRFManager.swift in Sources */, 145 | 4CACBDF61C0B6F6D006A9937 /* AppDelegate.swift in Sources */, 146 | ); 147 | runOnlyForDeploymentPostprocessing = 0; 148 | }; 149 | /* End PBXSourcesBuildPhase section */ 150 | 151 | /* Begin PBXVariantGroup section */ 152 | 4CACBDF91C0B6F6D006A9937 /* Main.storyboard */ = { 153 | isa = PBXVariantGroup; 154 | children = ( 155 | 4CACBDFA1C0B6F6D006A9937 /* Base */, 156 | ); 157 | name = Main.storyboard; 158 | sourceTree = ""; 159 | }; 160 | 4CACBDFE1C0B6F6D006A9937 /* LaunchScreen.storyboard */ = { 161 | isa = PBXVariantGroup; 162 | children = ( 163 | 4CACBDFF1C0B6F6D006A9937 /* Base */, 164 | ); 165 | name = LaunchScreen.storyboard; 166 | sourceTree = ""; 167 | }; 168 | /* End PBXVariantGroup section */ 169 | 170 | /* Begin XCBuildConfiguration section */ 171 | 4CACBE021C0B6F6D006A9937 /* Debug */ = { 172 | isa = XCBuildConfiguration; 173 | buildSettings = { 174 | ALWAYS_SEARCH_USER_PATHS = NO; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_WARN_BOOL_CONVERSION = YES; 180 | CLANG_WARN_CONSTANT_CONVERSION = YES; 181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 182 | CLANG_WARN_EMPTY_BODY = YES; 183 | CLANG_WARN_ENUM_CONVERSION = YES; 184 | CLANG_WARN_INFINITE_RECURSION = YES; 185 | CLANG_WARN_INT_CONVERSION = YES; 186 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 187 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 188 | CLANG_WARN_UNREACHABLE_CODE = YES; 189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 190 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 191 | COPY_PHASE_STRIP = NO; 192 | DEBUG_INFORMATION_FORMAT = dwarf; 193 | ENABLE_STRICT_OBJC_MSGSEND = YES; 194 | ENABLE_TESTABILITY = YES; 195 | GCC_C_LANGUAGE_STANDARD = gnu99; 196 | GCC_DYNAMIC_NO_PIC = NO; 197 | GCC_NO_COMMON_BLOCKS = YES; 198 | GCC_OPTIMIZATION_LEVEL = 0; 199 | GCC_PREPROCESSOR_DEFINITIONS = ( 200 | "DEBUG=1", 201 | "$(inherited)", 202 | ); 203 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 204 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 205 | GCC_WARN_UNDECLARED_SELECTOR = YES; 206 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 207 | GCC_WARN_UNUSED_FUNCTION = YES; 208 | GCC_WARN_UNUSED_VARIABLE = YES; 209 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 210 | MTL_ENABLE_DEBUG_INFO = YES; 211 | ONLY_ACTIVE_ARCH = YES; 212 | SDKROOT = iphoneos; 213 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 214 | TARGETED_DEVICE_FAMILY = "1,2"; 215 | }; 216 | name = Debug; 217 | }; 218 | 4CACBE031C0B6F6D006A9937 /* Release */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 223 | CLANG_CXX_LIBRARY = "libc++"; 224 | CLANG_ENABLE_MODULES = YES; 225 | CLANG_ENABLE_OBJC_ARC = YES; 226 | CLANG_WARN_BOOL_CONVERSION = YES; 227 | CLANG_WARN_CONSTANT_CONVERSION = YES; 228 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 229 | CLANG_WARN_EMPTY_BODY = YES; 230 | CLANG_WARN_ENUM_CONVERSION = YES; 231 | CLANG_WARN_INFINITE_RECURSION = YES; 232 | CLANG_WARN_INT_CONVERSION = YES; 233 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 234 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 235 | CLANG_WARN_UNREACHABLE_CODE = YES; 236 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 237 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 238 | COPY_PHASE_STRIP = NO; 239 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 240 | ENABLE_NS_ASSERTIONS = NO; 241 | ENABLE_STRICT_OBJC_MSGSEND = YES; 242 | GCC_C_LANGUAGE_STANDARD = gnu99; 243 | GCC_NO_COMMON_BLOCKS = YES; 244 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 245 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 246 | GCC_WARN_UNDECLARED_SELECTOR = YES; 247 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 248 | GCC_WARN_UNUSED_FUNCTION = YES; 249 | GCC_WARN_UNUSED_VARIABLE = YES; 250 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 251 | MTL_ENABLE_DEBUG_INFO = NO; 252 | SDKROOT = iphoneos; 253 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 254 | TARGETED_DEVICE_FAMILY = "1,2"; 255 | VALIDATE_PRODUCT = YES; 256 | }; 257 | name = Release; 258 | }; 259 | 4CACBE051C0B6F6D006A9937 /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 263 | DEVELOPMENT_TEAM = 54JDK55DR5; 264 | INFOPLIST_FILE = "nRF8001-Swift/Info.plist"; 265 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 266 | PRODUCT_BUNDLE_IDENTIFIER = "nl.xonaymedia.nRF8001-Swift"; 267 | PRODUCT_NAME = "$(TARGET_NAME)"; 268 | SWIFT_VERSION = 3.0; 269 | }; 270 | name = Debug; 271 | }; 272 | 4CACBE061C0B6F6D006A9937 /* Release */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 276 | DEVELOPMENT_TEAM = 54JDK55DR5; 277 | INFOPLIST_FILE = "nRF8001-Swift/Info.plist"; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = "nl.xonaymedia.nRF8001-Swift"; 280 | PRODUCT_NAME = "$(TARGET_NAME)"; 281 | SWIFT_VERSION = 3.0; 282 | }; 283 | name = Release; 284 | }; 285 | /* End XCBuildConfiguration section */ 286 | 287 | /* Begin XCConfigurationList section */ 288 | 4CACBDED1C0B6F6D006A9937 /* Build configuration list for PBXProject "nRF8001-Swift" */ = { 289 | isa = XCConfigurationList; 290 | buildConfigurations = ( 291 | 4CACBE021C0B6F6D006A9937 /* Debug */, 292 | 4CACBE031C0B6F6D006A9937 /* Release */, 293 | ); 294 | defaultConfigurationIsVisible = 0; 295 | defaultConfigurationName = Release; 296 | }; 297 | 4CACBE041C0B6F6D006A9937 /* Build configuration list for PBXNativeTarget "nRF8001-Swift" */ = { 298 | isa = XCConfigurationList; 299 | buildConfigurations = ( 300 | 4CACBE051C0B6F6D006A9937 /* Debug */, 301 | 4CACBE061C0B6F6D006A9937 /* Release */, 302 | ); 303 | defaultConfigurationIsVisible = 0; 304 | defaultConfigurationName = Release; 305 | }; 306 | /* End XCConfigurationList section */ 307 | }; 308 | rootObject = 4CACBDEA1C0B6F6D006A9937 /* Project object */; 309 | } 310 | -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/project.xcworkspace/xcuserdata/developer.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichMich/nRF8001-Swift/4231966aa13f5440f8fd379eaf51875b0ef0c643/nRF8001-Swift.xcodeproj/project.xcworkspace/xcuserdata/developer.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/xcuserdata/Michael.xcuserdatad/xcschemes/nRF8001-Swift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/xcuserdata/Michael.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | nRF8001-Swift.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 4CACBDF11C0B6F6D006A9937 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/xcuserdata/developer.xcuserdatad/xcschemes/nRF8001-Swift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /nRF8001-Swift.xcodeproj/xcuserdata/developer.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | nRF8001-Swift.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 4CACBDF11C0B6F6D006A9937 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /nRF8001-Swift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // nRF8001-Swift 4 | // 5 | // Created by Michael Teeuw on 29-11-15. 6 | // Copyright © 2015 Michael Teeuw. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /nRF8001-Swift/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /nRF8001-Swift/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /nRF8001-Swift/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /nRF8001-Swift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /nRF8001-Swift/NRFManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NRFManager.swift 3 | // nRF8001-Swift 4 | // 5 | // Created by Michael Teeuw on 31-07-14. 6 | // Copyright (c) 2014 Michael Teeuw. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreBluetooth 11 | 12 | 13 | public enum ConnectionMode { 14 | case none 15 | case pinIO 16 | case uart 17 | } 18 | 19 | public enum ConnectionStatus { 20 | case disconnected 21 | case scanning 22 | case connected 23 | } 24 | 25 | 26 | 27 | /*! 28 | * @class NRFManager 29 | * 30 | * @discussion The manager for nRF8001 connections. 31 | * 32 | */ 33 | 34 | // Mark: NRFManager Initialization 35 | open class NRFManager:NSObject, CBCentralManagerDelegate, UARTPeripheralDelegate { 36 | 37 | 38 | fileprivate var arduinoToConnect: String? 39 | //Private Properties 40 | fileprivate var bluetoothManager:CBCentralManager! 41 | fileprivate var currentPeripheral: UARTPeripheral? { 42 | didSet { 43 | if let p = currentPeripheral { 44 | p.verbose = self.verbose 45 | } 46 | } 47 | } 48 | 49 | //Public Properties 50 | open var verbose = false 51 | open var autoConnect = true 52 | open var delegate:NRFManagerDelegate? 53 | 54 | //callbacks 55 | open var connectionCallback:(()->())? 56 | open var disconnectionCallback:(()->())? 57 | open var dataCallback:((_ data:Data?, _ string:String?)->())? 58 | 59 | open fileprivate(set) var connectionMode = ConnectionMode.none 60 | open fileprivate(set) var connectionStatus:ConnectionStatus = ConnectionStatus.disconnected { 61 | didSet { 62 | if connectionStatus != oldValue { 63 | switch connectionStatus { 64 | case .connected: 65 | 66 | connectionCallback?() 67 | delegate?.nrfDidConnect?(self) 68 | 69 | default: 70 | 71 | disconnectionCallback?() 72 | delegate?.nrfDidDisconnect?(self) 73 | } 74 | } 75 | } 76 | } 77 | 78 | open func showName() -> String { 79 | return (currentPeripheral?.peripheral.name)! 80 | } 81 | 82 | 83 | 84 | 85 | open class var sharedInstance : NRFManager { 86 | struct Static { 87 | static let instance : NRFManager = NRFManager() 88 | } 89 | return Static.instance 90 | } 91 | 92 | public init(delegate:NRFManagerDelegate? = nil, onConnect connectionCallback:(()->())? = nil, onDisconnect disconnectionCallback:(()->())? = nil, onData dataCallback:((_ data:Data?, _ string:String?)->())? = nil, autoConnect:Bool = true) 93 | { 94 | super.init() 95 | self.delegate = delegate 96 | self.autoConnect = autoConnect 97 | bluetoothManager = CBCentralManager(delegate: self, queue: nil) 98 | self.connectionCallback = connectionCallback 99 | self.disconnectionCallback = disconnectionCallback 100 | self.dataCallback = dataCallback 101 | } 102 | 103 | } 104 | 105 | // MARK: - Private Methods 106 | extension NRFManager { 107 | 108 | fileprivate func scanForPeripheral() 109 | { 110 | let connectedPeripherals = bluetoothManager.retrieveConnectedPeripherals(withServices: [UARTPeripheral.uartServiceUUID()]) 111 | 112 | if connectedPeripherals.count > 0 { 113 | log("Already connected ...") 114 | connectPeripheral(connectedPeripherals[0] as CBPeripheral) 115 | } else { 116 | log("Scan for Peripherials") 117 | bluetoothManager.scanForPeripherals(withServices: [UARTPeripheral.uartServiceUUID()], options: [CBCentralManagerScanOptionAllowDuplicatesKey:false]) 118 | } 119 | } 120 | 121 | fileprivate func connectPeripheral(_ peripheral:CBPeripheral) { 122 | log("Connect to Peripheral: \(peripheral)") 123 | 124 | bluetoothManager.cancelPeripheralConnection(peripheral) 125 | 126 | currentPeripheral = UARTPeripheral(peripheral: peripheral, delegate: self) 127 | 128 | bluetoothManager.connect(peripheral, options: [CBConnectPeripheralOptionNotifyOnDisconnectionKey:false]) 129 | } 130 | 131 | fileprivate func alertBluetoothPowerOff() { 132 | log("Bluetooth disabled"); 133 | disconnect() 134 | } 135 | 136 | fileprivate func alertFailedConnection() { 137 | log("Unable to connect"); 138 | } 139 | 140 | fileprivate func log(_ logMessage: String) { 141 | if (verbose) { 142 | print("NRFManager: \(logMessage)") 143 | } 144 | } 145 | } 146 | 147 | // MARK: - Public Methods 148 | extension NRFManager { 149 | 150 | public func connect(_ arduinoName: String) { 151 | if currentPeripheral != nil && connectionStatus == .connected { 152 | log("Asked to connect, but already connected!") 153 | return 154 | } 155 | self.arduinoToConnect = arduinoName 156 | scanForPeripheral() 157 | } 158 | 159 | public func disconnect() 160 | { 161 | if currentPeripheral == nil { 162 | log("Asked to disconnect, but no current connection!") 163 | return 164 | } 165 | 166 | log("Disconnect ...") 167 | bluetoothManager.cancelPeripheralConnection((currentPeripheral?.peripheral)!) 168 | } 169 | 170 | public func writeString(_ string:String) -> Bool 171 | { 172 | if let currentPeripheral = self.currentPeripheral { 173 | if connectionStatus == .connected { 174 | currentPeripheral.writeString(string) 175 | return true 176 | } 177 | } 178 | log("Can't send string. No connection!") 179 | return false 180 | } 181 | 182 | public func writeData(_ data:Data) -> Bool 183 | { 184 | if let currentPeripheral = self.currentPeripheral { 185 | if connectionStatus == .connected { 186 | currentPeripheral.writeRawData(data) 187 | return true 188 | } 189 | } 190 | log("Can't send data. No connection!") 191 | return false 192 | } 193 | 194 | } 195 | 196 | // MARK: - CBCentralManagerDelegate Methods 197 | extension NRFManager { 198 | 199 | public func centralManagerDidUpdateState(_ central: CBCentralManager) 200 | { 201 | log("Central Manager Did UpdateState") 202 | if central.state == .poweredOn { 203 | //respond to powered on 204 | log("Powered on!") 205 | if (autoConnect) { 206 | connect("") 207 | } 208 | 209 | } else if central.state == .poweredOff { 210 | log("Powered off!") 211 | connectionStatus = ConnectionStatus.disconnected 212 | connectionMode = ConnectionMode.none 213 | } 214 | } 215 | 216 | @objc(centralManager:didDiscoverPeripheral:advertisementData:RSSI:) public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) 217 | { 218 | log("Did discover peripheral: \(peripheral.name!)") 219 | //bluetoothManager.stopScan() 220 | 221 | if peripheral.name == arduinoToConnect{ 222 | connectPeripheral(peripheral) 223 | } 224 | 225 | } 226 | 227 | @objc(centralManager:didConnectPeripheral:) public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) 228 | { 229 | log("Did Connect Peripheral") 230 | if currentPeripheral?.peripheral == peripheral { 231 | if (peripheral.services) != nil { 232 | log("Did connect to existing peripheral: \(peripheral.name)") 233 | currentPeripheral?.peripheral(peripheral, didDiscoverServices: nil) 234 | } else { 235 | log("Did connect peripheral: \(peripheral.name!)") 236 | currentPeripheral?.didConnect() 237 | } 238 | } 239 | } 240 | 241 | public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) 242 | { 243 | log("Peripheral Disconnected: \(peripheral.name)") 244 | 245 | if currentPeripheral?.peripheral == peripheral { 246 | connectionStatus = ConnectionStatus.disconnected 247 | connectionMode = ConnectionMode.none 248 | currentPeripheral = nil 249 | } 250 | 251 | if autoConnect { 252 | connect("") 253 | } 254 | } 255 | 256 | 257 | 258 | //optional func centralManager(central: CBCentralManager!, willRestoreState dict: [NSObject : AnyObject]!) 259 | //optional func centralManager(central: CBCentralManager!, didRetrievePeripherals peripherals: [AnyObject]!) 260 | //optional func centralManager(central: CBCentralManager!, didRetrieveConnectedPeripherals peripherals: [AnyObject]!) 261 | //optional func centralManager(central: CBCentralManager!, didFailToConnectPeripheral peripheral: CBPeripheral!, error: NSError!) 262 | } 263 | 264 | // MARK: - UARTPeripheralDelegate Methods 265 | extension NRFManager { 266 | 267 | public func didReceiveData(_ newData:Data) 268 | { 269 | if connectionStatus == .connected || connectionStatus == .scanning { 270 | log("Data: \(newData)"); 271 | 272 | let string = NSString(data: newData, encoding:String.Encoding.utf8.rawValue) 273 | log("String: \(string)") 274 | 275 | dataCallback?(newData, string! as String) 276 | delegate?.nrfReceivedData?(self, data:newData, string: string! as String) 277 | 278 | } 279 | } 280 | 281 | public func didReadHardwareRevisionString(_ string:String) 282 | { 283 | log("HW Revision: \(string)") 284 | connectionStatus = .connected 285 | } 286 | 287 | public func uartDidEncounterError(_ error:String) 288 | { 289 | log("Error: error") 290 | } 291 | 292 | } 293 | 294 | 295 | // MARK: NRFManagerDelegate Definition 296 | @objc public protocol NRFManagerDelegate { 297 | @objc optional func nrfDidConnect(_ nrfManager:NRFManager) 298 | @objc optional func nrfDidDisconnect(_ nrfManager:NRFManager) 299 | @objc optional func nrfReceivedData(_ nrfManager:NRFManager, data:Data?, string:String?) 300 | } 301 | 302 | 303 | /*! 304 | * @class UARTPeripheral 305 | * 306 | * @discussion The peripheral object used by NRFManager. 307 | * 308 | */ 309 | 310 | // MARK: UARTPeripheral Initialization 311 | open class UARTPeripheral:NSObject, CBPeripheralDelegate { 312 | 313 | fileprivate var peripheral:CBPeripheral 314 | fileprivate var uartService:CBService? 315 | fileprivate var rxCharacteristic:CBCharacteristic? 316 | fileprivate var txCharacteristic:CBCharacteristic? 317 | 318 | fileprivate var delegate:UARTPeripheralDelegate 319 | fileprivate var verbose = false 320 | 321 | fileprivate init(peripheral:CBPeripheral, delegate:UARTPeripheralDelegate) 322 | { 323 | 324 | self.peripheral = peripheral 325 | self.delegate = delegate 326 | 327 | super.init() 328 | 329 | self.peripheral.delegate = self 330 | } 331 | } 332 | 333 | // MARK: Private Methods 334 | extension UARTPeripheral { 335 | 336 | fileprivate func compareID(_ firstID:CBUUID, toID secondID:CBUUID)->Bool { 337 | return firstID.uuidString == secondID.uuidString 338 | 339 | } 340 | 341 | fileprivate func setupPeripheralForUse(_ peripheral:CBPeripheral) 342 | { 343 | log("Set up peripheral for use"); 344 | if let services = peripheral.services { 345 | for service:CBService in services { 346 | if let characteristics = service.characteristics { 347 | for characteristic:CBCharacteristic in characteristics { 348 | if compareID(characteristic.uuid, toID: UARTPeripheral.rxCharacteristicsUUID()) { 349 | log("Found RX Characteristics") 350 | rxCharacteristic = characteristic 351 | peripheral.setNotifyValue(true, for: rxCharacteristic!) 352 | } else if compareID(characteristic.uuid, toID: UARTPeripheral.txCharacteristicsUUID()) { 353 | log("Found TX Characteristics") 354 | txCharacteristic = characteristic 355 | } else if compareID(characteristic.uuid, toID: UARTPeripheral.hardwareRevisionStringUUID()) { 356 | log("Found Hardware Revision String characteristic") 357 | peripheral.readValue(for: characteristic) 358 | } 359 | } 360 | } 361 | } 362 | } 363 | } 364 | 365 | fileprivate func log(_ logMessage: String) { 366 | if (verbose) { 367 | print("UARTPeripheral: \(logMessage)") 368 | } 369 | } 370 | 371 | fileprivate func didConnect() 372 | { 373 | log("Did connect") 374 | if peripheral.services != nil { 375 | log("Skipping service discovery for: \(peripheral.name!)") 376 | peripheral(peripheral, didDiscoverServices: nil) 377 | return 378 | } 379 | 380 | log("Start service discovery: \(peripheral.name!)") 381 | peripheral.discoverServices([UARTPeripheral.uartServiceUUID(), UARTPeripheral.deviceInformationServiceUUID()]) 382 | } 383 | 384 | fileprivate func writeString(_ string:String) 385 | { 386 | log("Write string: \(string)") 387 | let data = Data(bytes: UnsafePointer(string), count: string.characters.count) 388 | writeRawData(data) 389 | } 390 | 391 | fileprivate func writeRawData(_ data:Data) 392 | { 393 | log("Write data: \(data)") 394 | 395 | if let txCharacteristic = self.txCharacteristic { 396 | 397 | if txCharacteristic.properties.intersection(.writeWithoutResponse) != [] { 398 | peripheral.writeValue(data, for: txCharacteristic, type: .withoutResponse) 399 | } else if txCharacteristic.properties.intersection(.write) != [] { 400 | peripheral.writeValue(data, for: txCharacteristic, type: .withResponse) 401 | } else { 402 | log("No write property on TX characteristics: \(txCharacteristic.properties)") 403 | } 404 | 405 | } 406 | } 407 | } 408 | 409 | // MARK: CBPeripheral Delegate methods 410 | extension UARTPeripheral { 411 | public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error:Error?) { 412 | 413 | if error == nil { 414 | if let services = peripheral.services { 415 | for service:CBService in services { 416 | if service.characteristics != nil { 417 | //var e = NSError() 418 | //peripheral(peripheral, didDiscoverCharacteristicsForService: s, error: e) 419 | } else if compareID(service.uuid, toID: UARTPeripheral.uartServiceUUID()) { 420 | log("Found correct service") 421 | uartService = service 422 | peripheral.discoverCharacteristics([UARTPeripheral.txCharacteristicsUUID(),UARTPeripheral.rxCharacteristicsUUID()], for: uartService!) 423 | } else if compareID(service.uuid, toID: UARTPeripheral.deviceInformationServiceUUID()) { 424 | peripheral.discoverCharacteristics([UARTPeripheral.hardwareRevisionStringUUID()], for: service) 425 | } 426 | } 427 | } 428 | } else { 429 | log("Error discovering characteristics: \(error)") 430 | delegate.uartDidEncounterError("Error discovering services") 431 | return 432 | } 433 | } 434 | 435 | @objc(peripheral:didDiscoverCharacteristicsForService:error:) public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) 436 | { 437 | if error == nil { 438 | log("Did Discover Characteristics For Service: \(service.description)") 439 | if let services = peripheral.services { 440 | let s = services[services.count - 1] 441 | if compareID(service.uuid, toID: s.uuid) { 442 | setupPeripheralForUse(peripheral) 443 | } 444 | } 445 | } else { 446 | log("Error discovering characteristics: \(error)") 447 | delegate.uartDidEncounterError("Error discovering characteristics") 448 | return 449 | } 450 | } 451 | 452 | @objc(peripheral:didUpdateValueForCharacteristic:error:) public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) 453 | { 454 | log("Did Update Value For Characteristic") 455 | if error == nil { 456 | if characteristic == rxCharacteristic { 457 | if let value = characteristic.value { 458 | log("Recieved: \(value)") 459 | delegate.didReceiveData(value) 460 | } 461 | } else if compareID(characteristic.uuid, toID: UARTPeripheral.hardwareRevisionStringUUID()){ 462 | log("Did read hardware revision string") 463 | // FIX ME: This is not how the original thing worked. 464 | delegate.didReadHardwareRevisionString(NSString(cString:characteristic.description, encoding: String.Encoding.utf8.rawValue)! as String) 465 | 466 | } 467 | } else { 468 | log("Error receiving notification for characteristic: \(error)") 469 | delegate.uartDidEncounterError("Error receiving notification for characteristic") 470 | return 471 | } 472 | } 473 | } 474 | 475 | // MARK: Class Methods 476 | extension UARTPeripheral { 477 | class func uartServiceUUID() -> CBUUID { 478 | return CBUUID(string:"6e400001-b5a3-f393-e0a9-e50e24dcca9e") 479 | } 480 | 481 | class func txCharacteristicsUUID() -> CBUUID { 482 | return CBUUID(string:"6e400002-b5a3-f393-e0a9-e50e24dcca9e") 483 | } 484 | 485 | class func rxCharacteristicsUUID() -> CBUUID { 486 | return CBUUID(string:"6e400003-b5a3-f393-e0a9-e50e24dcca9e") 487 | } 488 | 489 | class func deviceInformationServiceUUID() -> CBUUID{ 490 | return CBUUID(string:"180A") 491 | } 492 | 493 | class func hardwareRevisionStringUUID() -> CBUUID{ 494 | return CBUUID(string:"2A27") 495 | } 496 | } 497 | 498 | // MARK: UARTPeripheralDelegate Definition 499 | private protocol UARTPeripheralDelegate { 500 | func didReceiveData(_ newData:Data) 501 | func didReadHardwareRevisionString(_ string:String) 502 | func uartDidEncounterError(_ error:String) 503 | } 504 | -------------------------------------------------------------------------------- /nRF8001-Swift/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // nRF8001-Swift 4 | // 5 | // Created by Michael Teeuw on 31-07-14. 6 | // Copyright (c) 2014 Michael Teeuw. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController, NRFManagerDelegate { 12 | 13 | var nrfManager:NRFManager! 14 | var feedbackView = UITextView() 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | nrfManager = NRFManager( 20 | onConnect: { 21 | self.log("C: ★ Connected") 22 | }, 23 | onDisconnect: { 24 | self.log("C: ★ Disconnected") 25 | }, 26 | onData: { 27 | (data:Data?, string:String?)->() in 28 | self.log("C: ⬇ Received data - String: \(string) - Data: \(data)") 29 | }, 30 | autoConnect: false 31 | ) 32 | 33 | nrfManager.verbose = true 34 | nrfManager.delegate = self 35 | 36 | setupUI() 37 | } 38 | 39 | func sendData() 40 | { 41 | let string = "Whoot!" 42 | let result = self.nrfManager.writeString(string) 43 | log("⬆ Sent string: \(string) - Result: \(result)") 44 | } 45 | } 46 | 47 | // MARK: - NRFManagerDelegate Methods 48 | extension ViewController 49 | { 50 | func nrfDidConnect(_ nrfManager:NRFManager) 51 | { 52 | self.log("D: ★ Connected") 53 | } 54 | 55 | func nrfDidDisconnect(_ nrfManager:NRFManager) 56 | { 57 | self.log("D: ★ Disconnected") 58 | } 59 | 60 | func nrfReceivedData(_ nrfManager:NRFManager, data: Data?, string: String?) { 61 | self.log("D: ⬇ Received data - String: \(string) - Data: \(data)") 62 | } 63 | } 64 | 65 | // MARK: - Various stuff 66 | extension ViewController { 67 | func setupUI() 68 | { 69 | view.addSubview(feedbackView) 70 | feedbackView.translatesAutoresizingMaskIntoConstraints = false 71 | feedbackView.layer.borderWidth = 1 72 | feedbackView.isEditable = false 73 | 74 | let connectButton:UIButton = UIButton(type: .system) 75 | view.addSubview(connectButton) 76 | connectButton.setTitle("Connect", for: UIControlState()) 77 | connectButton.translatesAutoresizingMaskIntoConstraints = false 78 | connectButton.addTarget(nrfManager, action: Selector(("connect")), for: UIControlEvents.touchUpInside) 79 | 80 | let disconnectButton:UIButton = UIButton(type: .system) 81 | view.addSubview(disconnectButton) 82 | disconnectButton.setTitle("Disconnect", for: UIControlState()) 83 | disconnectButton.translatesAutoresizingMaskIntoConstraints = false 84 | disconnectButton.addTarget(nrfManager, action: Selector(("disconnect")), for: UIControlEvents.touchUpInside) 85 | 86 | let sendButton:UIButton = UIButton(type: .system) 87 | view.addSubview(sendButton) 88 | sendButton.setTitle("Send Data", for: UIControlState()) 89 | sendButton.translatesAutoresizingMaskIntoConstraints = false 90 | sendButton.addTarget(self, action: #selector(ViewController.sendData), for: UIControlEvents.touchUpInside) 91 | 92 | 93 | view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[f]-|", options: [], metrics: nil, views: ["f":feedbackView])) 94 | view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[c]-|", options: [], metrics: nil, views: ["c":connectButton])) 95 | view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[d]-|", options: [], metrics: nil, views: ["d":disconnectButton])) 96 | view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[s]-|", options: [], metrics: nil, views: ["s":sendButton])) 97 | view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-20-[f]-[c]-[d]-[s]-20-|", options: [], metrics: nil, views: ["f":feedbackView,"c":connectButton,"d":disconnectButton,"s":sendButton])) 98 | } 99 | 100 | func log(_ string:String) 101 | { 102 | print(string) 103 | feedbackView.text = feedbackView.text + "\(string)\n" 104 | feedbackView.scrollRangeToVisible(NSMakeRange(feedbackView.text.characters.count , 1)) 105 | } 106 | 107 | } 108 | 109 | --------------------------------------------------------------------------------