├── .gitignore ├── Basic Chat MVC.xcodeproj └── project.pbxproj ├── Basic Chat MVC ├── AppDelegate.swift ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Controllers │ ├── ConsoleViewController.swift │ └── ViewController.swift ├── Info.plist ├── Model │ ├── BlePeripheral.swift │ └── CBUUIDs.swift ├── SceneDelegate.swift └── View │ └── TableViewCell.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.WAV 3 | App stuff/Friend Profile/ 4 | 5 | # Xcode 6 | # 7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 8 | # From: https://github.com/github/gitignore/edit/master/Objective-C.gitignore 9 | 10 | ## User settings 11 | xcuserdata/ 12 | 13 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 14 | *.xcscmblueprint 15 | *.xccheckout 16 | 17 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 18 | build/ 19 | DerivedData/ 20 | *.moved-aside 21 | *.pbxuser 22 | !default.pbxuser 23 | *.mode1v3 24 | !default.mode1v3 25 | *.mode2v3 26 | !default.mode2v3 27 | *.perspectivev3 28 | !default.perspectivev3 29 | 30 | ## Obj-C/Swift specific 31 | *.hmap 32 | 33 | ## App packaging 34 | *.ipa 35 | *.dSYM.zip 36 | *.dSYM 37 | 38 | # CocoaPods 39 | # 40 | # We recommend against adding the Pods directory to your .gitignore. However 41 | # you should judge for yourself, the pros and cons are mentioned at: 42 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 43 | # 44 | # Pods/ 45 | # 46 | # Add this line if you want to avoid checking in source code from the Xcode workspace 47 | # *.xcworkspace 48 | 49 | # Carthage 50 | # 51 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 52 | # Carthage/Checkouts 53 | 54 | Carthage/Build/ 55 | 56 | # fastlane 57 | # 58 | # It is recommended to not store the screenshots in the git repo. 59 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 60 | # For more information about the recommended setup visit: 61 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 62 | 63 | fastlane/report.xml 64 | fastlane/Preview.html 65 | fastlane/screenshots/**/*.png 66 | fastlane/test_output 67 | 68 | # Code Injection 69 | # 70 | # After new code Injection tools there's a generated folder /iOSInjectionProject 71 | # https://github.com/johnno1962/injectionforxcode 72 | 73 | iOSInjectionProject/ 74 | 75 | -------------------------------------------------------------------------------- /Basic Chat MVC.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 29A1DF4925CB1D7F000A9A84 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1DF4825CB1D7F000A9A84 /* AppDelegate.swift */; }; 11 | 29A1DF4B25CB1D7F000A9A84 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1DF4A25CB1D7F000A9A84 /* SceneDelegate.swift */; }; 12 | 29A1DF4D25CB1D7F000A9A84 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1DF4C25CB1D7F000A9A84 /* ViewController.swift */; }; 13 | 29A1DF5025CB1D7F000A9A84 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29A1DF4E25CB1D7F000A9A84 /* Main.storyboard */; }; 14 | 29A1DF5225CB1D82000A9A84 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29A1DF5125CB1D82000A9A84 /* Assets.xcassets */; }; 15 | 29A1DF5525CB1D82000A9A84 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29A1DF5325CB1D82000A9A84 /* LaunchScreen.storyboard */; }; 16 | 29A1DF6225CBA309000A9A84 /* CBUUIDs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1DF6125CBA309000A9A84 /* CBUUIDs.swift */; }; 17 | 29A1DF6725CBB6E4000A9A84 /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1DF6625CBB6E4000A9A84 /* TableViewCell.swift */; }; 18 | 29A1DF7025CF0560000A9A84 /* ConsoleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1DF6F25CF0560000A9A84 /* ConsoleViewController.swift */; }; 19 | 29DEAA1225D9A787002AECEC /* BlePeripheral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29DEAA1125D9A787002AECEC /* BlePeripheral.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 29A1DF4525CB1D7F000A9A84 /* Basic Chat MVC.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Basic Chat MVC.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 29A1DF4825CB1D7F000A9A84 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | 29A1DF4A25CB1D7F000A9A84 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 26 | 29A1DF4C25CB1D7F000A9A84 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 27 | 29A1DF4F25CB1D7F000A9A84 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 28 | 29A1DF5125CB1D82000A9A84 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29 | 29A1DF5425CB1D82000A9A84 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 30 | 29A1DF5625CB1D82000A9A84 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 29A1DF6125CBA309000A9A84 /* CBUUIDs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CBUUIDs.swift; sourceTree = ""; }; 32 | 29A1DF6625CBB6E4000A9A84 /* TableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = ""; }; 33 | 29A1DF6F25CF0560000A9A84 /* ConsoleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleViewController.swift; sourceTree = ""; }; 34 | 29DEAA1125D9A787002AECEC /* BlePeripheral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlePeripheral.swift; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 29A1DF4225CB1D7F000A9A84 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 2970B39225DF554A001CF3CF /* Model */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 29DEAA1125D9A787002AECEC /* BlePeripheral.swift */, 52 | 29A1DF6125CBA309000A9A84 /* CBUUIDs.swift */, 53 | ); 54 | path = Model; 55 | sourceTree = ""; 56 | }; 57 | 2970B39325DF555D001CF3CF /* Controllers */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 29A1DF4C25CB1D7F000A9A84 /* ViewController.swift */, 61 | 29A1DF6F25CF0560000A9A84 /* ConsoleViewController.swift */, 62 | ); 63 | path = Controllers; 64 | sourceTree = ""; 65 | }; 66 | 2970B39525DF5570001CF3CF /* View */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 29A1DF6625CBB6E4000A9A84 /* TableViewCell.swift */, 70 | ); 71 | path = View; 72 | sourceTree = ""; 73 | }; 74 | 29A1DF3C25CB1D7F000A9A84 = { 75 | isa = PBXGroup; 76 | children = ( 77 | 29A1DF4725CB1D7F000A9A84 /* Basic Chat MVC */, 78 | 29A1DF4625CB1D7F000A9A84 /* Products */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | 29A1DF4625CB1D7F000A9A84 /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 29A1DF4525CB1D7F000A9A84 /* Basic Chat MVC.app */, 86 | ); 87 | name = Products; 88 | sourceTree = ""; 89 | }; 90 | 29A1DF4725CB1D7F000A9A84 /* Basic Chat MVC */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 29A1DF4825CB1D7F000A9A84 /* AppDelegate.swift */, 94 | 29A1DF4A25CB1D7F000A9A84 /* SceneDelegate.swift */, 95 | 2970B39225DF554A001CF3CF /* Model */, 96 | 2970B39525DF5570001CF3CF /* View */, 97 | 2970B39325DF555D001CF3CF /* Controllers */, 98 | 29A1DF4E25CB1D7F000A9A84 /* Main.storyboard */, 99 | 29A1DF5125CB1D82000A9A84 /* Assets.xcassets */, 100 | 29A1DF5325CB1D82000A9A84 /* LaunchScreen.storyboard */, 101 | 29A1DF5625CB1D82000A9A84 /* Info.plist */, 102 | ); 103 | path = "Basic Chat MVC"; 104 | sourceTree = ""; 105 | }; 106 | /* End PBXGroup section */ 107 | 108 | /* Begin PBXNativeTarget section */ 109 | 29A1DF4425CB1D7F000A9A84 /* Basic Chat MVC */ = { 110 | isa = PBXNativeTarget; 111 | buildConfigurationList = 29A1DF5925CB1D82000A9A84 /* Build configuration list for PBXNativeTarget "Basic Chat MVC" */; 112 | buildPhases = ( 113 | 29A1DF4125CB1D7F000A9A84 /* Sources */, 114 | 29A1DF4225CB1D7F000A9A84 /* Frameworks */, 115 | 29A1DF4325CB1D7F000A9A84 /* Resources */, 116 | ); 117 | buildRules = ( 118 | ); 119 | dependencies = ( 120 | ); 121 | name = "Basic Chat MVC"; 122 | productName = "Basic Chat MVC"; 123 | productReference = 29A1DF4525CB1D7F000A9A84 /* Basic Chat MVC.app */; 124 | productType = "com.apple.product-type.application"; 125 | }; 126 | /* End PBXNativeTarget section */ 127 | 128 | /* Begin PBXProject section */ 129 | 29A1DF3D25CB1D7F000A9A84 /* Project object */ = { 130 | isa = PBXProject; 131 | attributes = { 132 | LastSwiftUpdateCheck = 1200; 133 | LastUpgradeCheck = 1200; 134 | TargetAttributes = { 135 | 29A1DF4425CB1D7F000A9A84 = { 136 | CreatedOnToolsVersion = 12.0.1; 137 | }; 138 | }; 139 | }; 140 | buildConfigurationList = 29A1DF4025CB1D7F000A9A84 /* Build configuration list for PBXProject "Basic Chat MVC" */; 141 | compatibilityVersion = "Xcode 9.3"; 142 | developmentRegion = en; 143 | hasScannedForEncodings = 0; 144 | knownRegions = ( 145 | en, 146 | Base, 147 | ); 148 | mainGroup = 29A1DF3C25CB1D7F000A9A84; 149 | productRefGroup = 29A1DF4625CB1D7F000A9A84 /* Products */; 150 | projectDirPath = ""; 151 | projectRoot = ""; 152 | targets = ( 153 | 29A1DF4425CB1D7F000A9A84 /* Basic Chat MVC */, 154 | ); 155 | }; 156 | /* End PBXProject section */ 157 | 158 | /* Begin PBXResourcesBuildPhase section */ 159 | 29A1DF4325CB1D7F000A9A84 /* Resources */ = { 160 | isa = PBXResourcesBuildPhase; 161 | buildActionMask = 2147483647; 162 | files = ( 163 | 29A1DF5525CB1D82000A9A84 /* LaunchScreen.storyboard in Resources */, 164 | 29A1DF5225CB1D82000A9A84 /* Assets.xcassets in Resources */, 165 | 29A1DF5025CB1D7F000A9A84 /* Main.storyboard in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXSourcesBuildPhase section */ 172 | 29A1DF4125CB1D7F000A9A84 /* Sources */ = { 173 | isa = PBXSourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 29A1DF4D25CB1D7F000A9A84 /* ViewController.swift in Sources */, 177 | 29A1DF4925CB1D7F000A9A84 /* AppDelegate.swift in Sources */, 178 | 29A1DF6225CBA309000A9A84 /* CBUUIDs.swift in Sources */, 179 | 29A1DF7025CF0560000A9A84 /* ConsoleViewController.swift in Sources */, 180 | 29A1DF6725CBB6E4000A9A84 /* TableViewCell.swift in Sources */, 181 | 29A1DF4B25CB1D7F000A9A84 /* SceneDelegate.swift in Sources */, 182 | 29DEAA1225D9A787002AECEC /* BlePeripheral.swift in Sources */, 183 | ); 184 | runOnlyForDeploymentPostprocessing = 0; 185 | }; 186 | /* End PBXSourcesBuildPhase section */ 187 | 188 | /* Begin PBXVariantGroup section */ 189 | 29A1DF4E25CB1D7F000A9A84 /* Main.storyboard */ = { 190 | isa = PBXVariantGroup; 191 | children = ( 192 | 29A1DF4F25CB1D7F000A9A84 /* Base */, 193 | ); 194 | name = Main.storyboard; 195 | sourceTree = ""; 196 | }; 197 | 29A1DF5325CB1D82000A9A84 /* LaunchScreen.storyboard */ = { 198 | isa = PBXVariantGroup; 199 | children = ( 200 | 29A1DF5425CB1D82000A9A84 /* Base */, 201 | ); 202 | name = LaunchScreen.storyboard; 203 | sourceTree = ""; 204 | }; 205 | /* End PBXVariantGroup section */ 206 | 207 | /* Begin XCBuildConfiguration section */ 208 | 29A1DF5725CB1D82000A9A84 /* Debug */ = { 209 | isa = XCBuildConfiguration; 210 | buildSettings = { 211 | ALWAYS_SEARCH_USER_PATHS = NO; 212 | CLANG_ANALYZER_NONNULL = YES; 213 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 214 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 215 | CLANG_CXX_LIBRARY = "libc++"; 216 | CLANG_ENABLE_MODULES = YES; 217 | CLANG_ENABLE_OBJC_ARC = YES; 218 | CLANG_ENABLE_OBJC_WEAK = YES; 219 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 220 | CLANG_WARN_BOOL_CONVERSION = YES; 221 | CLANG_WARN_COMMA = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 224 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 225 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 226 | CLANG_WARN_EMPTY_BODY = YES; 227 | CLANG_WARN_ENUM_CONVERSION = YES; 228 | CLANG_WARN_INFINITE_RECURSION = YES; 229 | CLANG_WARN_INT_CONVERSION = YES; 230 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 231 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 232 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 233 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 234 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 235 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 236 | CLANG_WARN_STRICT_PROTOTYPES = YES; 237 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 238 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 239 | CLANG_WARN_UNREACHABLE_CODE = YES; 240 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = dwarf; 243 | ENABLE_STRICT_OBJC_MSGSEND = YES; 244 | ENABLE_TESTABILITY = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu11; 246 | GCC_DYNAMIC_NO_PIC = NO; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_OPTIMIZATION_LEVEL = 0; 249 | GCC_PREPROCESSOR_DEFINITIONS = ( 250 | "DEBUG=1", 251 | "$(inherited)", 252 | ); 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 260 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 261 | MTL_FAST_MATH = YES; 262 | ONLY_ACTIVE_ARCH = YES; 263 | SDKROOT = iphoneos; 264 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 265 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 266 | }; 267 | name = Debug; 268 | }; 269 | 29A1DF5825CB1D82000A9A84 /* Release */ = { 270 | isa = XCBuildConfiguration; 271 | buildSettings = { 272 | ALWAYS_SEARCH_USER_PATHS = NO; 273 | CLANG_ANALYZER_NONNULL = YES; 274 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 275 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 276 | CLANG_CXX_LIBRARY = "libc++"; 277 | CLANG_ENABLE_MODULES = YES; 278 | CLANG_ENABLE_OBJC_ARC = YES; 279 | CLANG_ENABLE_OBJC_WEAK = YES; 280 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 281 | CLANG_WARN_BOOL_CONVERSION = YES; 282 | CLANG_WARN_COMMA = YES; 283 | CLANG_WARN_CONSTANT_CONVERSION = YES; 284 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 285 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 286 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 287 | CLANG_WARN_EMPTY_BODY = YES; 288 | CLANG_WARN_ENUM_CONVERSION = YES; 289 | CLANG_WARN_INFINITE_RECURSION = YES; 290 | CLANG_WARN_INT_CONVERSION = YES; 291 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 292 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 293 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 296 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 297 | CLANG_WARN_STRICT_PROTOTYPES = YES; 298 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 299 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 300 | CLANG_WARN_UNREACHABLE_CODE = YES; 301 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 302 | COPY_PHASE_STRIP = NO; 303 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 304 | ENABLE_NS_ASSERTIONS = NO; 305 | ENABLE_STRICT_OBJC_MSGSEND = YES; 306 | GCC_C_LANGUAGE_STANDARD = gnu11; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 315 | MTL_ENABLE_DEBUG_INFO = NO; 316 | MTL_FAST_MATH = YES; 317 | SDKROOT = iphoneos; 318 | SWIFT_COMPILATION_MODE = wholemodule; 319 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 320 | VALIDATE_PRODUCT = YES; 321 | }; 322 | name = Release; 323 | }; 324 | 29A1DF5A25CB1D82000A9A84 /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 328 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 329 | CODE_SIGN_STYLE = Automatic; 330 | CURRENT_PROJECT_VERSION = 1; 331 | DEVELOPMENT_TEAM = 2X94RM7457; 332 | INFOPLIST_FILE = "Basic Chat MVC/Info.plist"; 333 | LD_RUNPATH_SEARCH_PATHS = ( 334 | "$(inherited)", 335 | "@executable_path/Frameworks", 336 | ); 337 | MARKETING_VERSION = 1; 338 | PRODUCT_BUNDLE_IDENTIFIER = "com.Adafruit.Industries.Basic-Chat"; 339 | PRODUCT_NAME = "$(TARGET_NAME)"; 340 | SWIFT_VERSION = 5.0; 341 | TARGETED_DEVICE_FAMILY = "1,2"; 342 | }; 343 | name = Debug; 344 | }; 345 | 29A1DF5B25CB1D82000A9A84 /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 349 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 350 | CODE_SIGN_STYLE = Automatic; 351 | CURRENT_PROJECT_VERSION = 1; 352 | DEVELOPMENT_TEAM = 2X94RM7457; 353 | INFOPLIST_FILE = "Basic Chat MVC/Info.plist"; 354 | LD_RUNPATH_SEARCH_PATHS = ( 355 | "$(inherited)", 356 | "@executable_path/Frameworks", 357 | ); 358 | MARKETING_VERSION = 1; 359 | PRODUCT_BUNDLE_IDENTIFIER = "com.Adafruit.Industries.Basic-Chat"; 360 | PRODUCT_NAME = "$(TARGET_NAME)"; 361 | SWIFT_VERSION = 5.0; 362 | TARGETED_DEVICE_FAMILY = "1,2"; 363 | }; 364 | name = Release; 365 | }; 366 | /* End XCBuildConfiguration section */ 367 | 368 | /* Begin XCConfigurationList section */ 369 | 29A1DF4025CB1D7F000A9A84 /* Build configuration list for PBXProject "Basic Chat MVC" */ = { 370 | isa = XCConfigurationList; 371 | buildConfigurations = ( 372 | 29A1DF5725CB1D82000A9A84 /* Debug */, 373 | 29A1DF5825CB1D82000A9A84 /* Release */, 374 | ); 375 | defaultConfigurationIsVisible = 0; 376 | defaultConfigurationName = Release; 377 | }; 378 | 29A1DF5925CB1D82000A9A84 /* Build configuration list for PBXNativeTarget "Basic Chat MVC" */ = { 379 | isa = XCConfigurationList; 380 | buildConfigurations = ( 381 | 29A1DF5A25CB1D82000A9A84 /* Debug */, 382 | 29A1DF5B25CB1D82000A9A84 /* Release */, 383 | ); 384 | defaultConfigurationIsVisible = 0; 385 | defaultConfigurationName = Release; 386 | }; 387 | /* End XCConfigurationList section */ 388 | }; 389 | rootObject = 29A1DF3D25CB1D7F000A9A84 /* Project object */; 390 | } 391 | -------------------------------------------------------------------------------- /Basic Chat MVC/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Basic Chat MVC 4 | // 5 | // Created by Trevor Beaton on 2/3/21. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Basic Chat MVC/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Basic Chat MVC/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Basic Chat MVC/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Basic Chat MVC/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 | -------------------------------------------------------------------------------- /Basic Chat MVC/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 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 62 | 69 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 106 | 112 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 167 | 168 | 169 | 170 | 179 | 188 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | -------------------------------------------------------------------------------- /Basic Chat MVC/Controllers/ConsoleViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConsoleViewController.swift 3 | // Basic Chat 4 | // 5 | // Created by Trevor Beaton on 2/6/21. 6 | // 7 | 8 | import UIKit 9 | import CoreBluetooth 10 | 11 | class ConsoleViewController: UIViewController { 12 | 13 | //Data 14 | var peripheralManager: CBPeripheralManager? 15 | var peripheral: CBPeripheral? 16 | var periperalTXCharacteristic: CBCharacteristic? 17 | 18 | @IBOutlet weak var peripheralLabel: UILabel! 19 | @IBOutlet weak var serviceLabel: UILabel! 20 | @IBOutlet weak var consoleTextView: UITextView! 21 | @IBOutlet weak var consoleTextField: UITextField! 22 | @IBOutlet weak var txLabel: UILabel! 23 | @IBOutlet weak var rxLabel: UILabel! 24 | 25 | override func viewDidLoad() { 26 | super.viewDidLoad() 27 | 28 | keyboardNotifications() 29 | 30 | NotificationCenter.default.addObserver(self, selector: #selector(self.appendRxDataToTextView(notification:)), name: NSNotification.Name(rawValue: "Notify"), object: nil) 31 | 32 | consoleTextField.delegate = self 33 | 34 | peripheralLabel.text = BlePeripheral.connectedPeripheral?.name 35 | 36 | txLabel.text = "TX:\(String(BlePeripheral.connectedTXChar!.uuid.uuidString))" 37 | rxLabel.text = "RX:\(String(BlePeripheral.connectedRXChar!.uuid.uuidString))" 38 | 39 | if let service = BlePeripheral.connectedService { 40 | serviceLabel.text = "Number of Services: \(String((BlePeripheral.connectedPeripheral?.services!.count)!))" 41 | } else{ 42 | print("Service was not found") 43 | } 44 | } 45 | 46 | @objc func appendRxDataToTextView(notification: Notification) -> Void{ 47 | consoleTextView.text.append("\n[Recv]: \(notification.object!) \n") 48 | } 49 | 50 | func appendTxDataToTextView(){ 51 | consoleTextView.text.append("\n[Sent]: \(String(consoleTextField.text!)) \n") 52 | } 53 | 54 | func keyboardNotifications() { 55 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) 56 | 57 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHide(notification:)), name: UIResponder.keyboardDidHideNotification, object: nil) 58 | 59 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange(notification:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil) 60 | } 61 | 62 | deinit { 63 | NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil) 64 | NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidHideNotification, object: nil) 65 | NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil) 66 | } 67 | 68 | // MARK:- Keyboard 69 | @objc func keyboardWillChange(notification: Notification) { 70 | 71 | if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { 72 | 73 | let keyboardHeight = keyboardSize.height 74 | print(keyboardHeight) 75 | view.frame.origin.y = (-keyboardHeight + 50) 76 | } 77 | } 78 | 79 | @objc func keyboardDidHide(notification: Notification) { 80 | view.frame.origin.y = 0 81 | } 82 | 83 | @objc func disconnectPeripheral() { 84 | print("Disconnect for peripheral.") 85 | } 86 | 87 | // Write functions 88 | func writeOutgoingValue(data: String){ 89 | let valueString = (data as NSString).data(using: String.Encoding.utf8.rawValue) 90 | //change the "data" to valueString 91 | if let blePeripheral = BlePeripheral.connectedPeripheral { 92 | if let txCharacteristic = BlePeripheral.connectedTXChar { 93 | blePeripheral.writeValue(valueString!, for: txCharacteristic, type: CBCharacteristicWriteType.withResponse) 94 | } 95 | } 96 | } 97 | 98 | func writeCharacteristic(incomingValue: Int8){ 99 | var val = incomingValue 100 | 101 | let outgoingData = NSData(bytes: &val, length: MemoryLayout.size) 102 | peripheral?.writeValue(outgoingData as Data, for: BlePeripheral.connectedTXChar!, type: CBCharacteristicWriteType.withResponse) 103 | } 104 | } 105 | 106 | extension ConsoleViewController: CBPeripheralManagerDelegate { 107 | 108 | func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { 109 | switch peripheral.state { 110 | case .poweredOn: 111 | print("Peripheral Is Powered On.") 112 | case .unsupported: 113 | print("Peripheral Is Unsupported.") 114 | case .unauthorized: 115 | print("Peripheral Is Unauthorized.") 116 | case .unknown: 117 | print("Peripheral Unknown") 118 | case .resetting: 119 | print("Peripheral Resetting") 120 | case .poweredOff: 121 | print("Peripheral Is Powered Off.") 122 | @unknown default: 123 | print("Error") 124 | } 125 | } 126 | 127 | 128 | //Check when someone subscribe to our characteristic, start sending the data 129 | func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic) { 130 | print("Device subscribe to characteristic") 131 | } 132 | 133 | } 134 | 135 | extension ConsoleViewController: UITextViewDelegate { 136 | 137 | } 138 | 139 | extension ConsoleViewController: UITextFieldDelegate { 140 | 141 | func textFieldShouldReturn(_ textField: UITextField) -> Bool { 142 | writeOutgoingValue(data: textField.text ?? "") 143 | appendTxDataToTextView() 144 | textField.resignFirstResponder() 145 | textField.text = "" 146 | return true 147 | 148 | } 149 | 150 | func textFieldShouldClear(_ textField: UITextField) -> Bool { 151 | textField.clearsOnBeginEditing = true 152 | return true 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /Basic Chat MVC/Controllers/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Basic Chat 4 | // 5 | // Created by Trevor Beaton on 2/3/21. 6 | // 7 | 8 | import UIKit 9 | import CoreBluetooth 10 | 11 | class ViewController: UIViewController { 12 | 13 | // Data 14 | private var centralManager: CBCentralManager! 15 | private var bluefruitPeripheral: CBPeripheral! 16 | private var txCharacteristic: CBCharacteristic! 17 | private var rxCharacteristic: CBCharacteristic! 18 | private var peripheralArray: [CBPeripheral] = [] 19 | private var rssiArray = [NSNumber]() 20 | private var timer = Timer() 21 | 22 | // UI 23 | @IBOutlet weak var tableView: UITableView! 24 | @IBOutlet weak var peripheralFoundLabel: UILabel! 25 | @IBOutlet weak var scanningLabel: UILabel! 26 | @IBOutlet weak var scanningButton: UIButton! 27 | 28 | @IBAction func scanningAction(_ sender: Any) { 29 | startScanning() 30 | } 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | self.tableView.delegate = self 36 | self.tableView.dataSource = self 37 | self.tableView.reloadData() 38 | // Manager 39 | centralManager = CBCentralManager(delegate: self, queue: nil) 40 | } 41 | 42 | override func viewDidAppear(_ animated: Bool) { 43 | disconnectFromDevice() 44 | self.tableView.reloadData() 45 | //startScanning() 46 | } 47 | 48 | func connectToDevice() -> Void { 49 | centralManager?.connect(bluefruitPeripheral!, options: nil) 50 | } 51 | 52 | func disconnectFromDevice() -> Void { 53 | if bluefruitPeripheral != nil { 54 | centralManager?.cancelPeripheralConnection(bluefruitPeripheral!) 55 | } 56 | } 57 | 58 | func removeArrayData() -> Void { 59 | centralManager.cancelPeripheralConnection(bluefruitPeripheral) 60 | rssiArray.removeAll() 61 | peripheralArray.removeAll() 62 | } 63 | 64 | func startScanning() -> Void { 65 | // Remove prior data 66 | peripheralArray.removeAll() 67 | rssiArray.removeAll() 68 | // Start Scanning 69 | centralManager?.scanForPeripherals(withServices: [CBUUIDs.BLEService_UUID]) 70 | scanningLabel.text = "Scanning..." 71 | scanningButton.isEnabled = false 72 | Timer.scheduledTimer(withTimeInterval: 15, repeats: false) {_ in 73 | self.stopScanning() 74 | } 75 | } 76 | 77 | func scanForBLEDevices() -> Void { 78 | // Remove prior data 79 | peripheralArray.removeAll() 80 | rssiArray.removeAll() 81 | // Start Scanning 82 | centralManager?.scanForPeripherals(withServices: [] , options: [CBCentralManagerScanOptionAllowDuplicatesKey:true]) 83 | scanningLabel.text = "Scanning..." 84 | 85 | Timer.scheduledTimer(withTimeInterval: 15, repeats: false) {_ in 86 | self.stopScanning() 87 | } 88 | } 89 | 90 | func stopTimer() -> Void { 91 | // Stops Timer 92 | self.timer.invalidate() 93 | } 94 | 95 | func stopScanning() -> Void { 96 | scanningLabel.text = "" 97 | scanningButton.isEnabled = true 98 | centralManager?.stopScan() 99 | } 100 | 101 | func delayedConnection() -> Void { 102 | 103 | BlePeripheral.connectedPeripheral = bluefruitPeripheral 104 | 105 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { 106 | //Once connected, move to new view controller to manager incoming and outgoing data 107 | let storyboard = UIStoryboard(name: "Main", bundle: nil) 108 | 109 | let detailViewController = storyboard.instantiateViewController(withIdentifier: "ConsoleViewController") as! ConsoleViewController 110 | 111 | self.navigationController?.pushViewController(detailViewController, animated: true) 112 | }) 113 | } 114 | } 115 | 116 | // MARK: - CBCentralManagerDelegate 117 | // A protocol that provides updates for the discovery and management of peripheral devices. 118 | extension ViewController: CBCentralManagerDelegate { 119 | 120 | // MARK: - Check 121 | func centralManagerDidUpdateState(_ central: CBCentralManager) { 122 | 123 | switch central.state { 124 | case .poweredOff: 125 | print("Is Powered Off.") 126 | 127 | let alertVC = UIAlertController(title: "Bluetooth Required", message: "Check your Bluetooth Settings", preferredStyle: UIAlertController.Style.alert) 128 | 129 | let action = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: { (action: UIAlertAction) -> Void in 130 | self.dismiss(animated: true, completion: nil) 131 | }) 132 | 133 | alertVC.addAction(action) 134 | 135 | self.present(alertVC, animated: true, completion: nil) 136 | 137 | case .poweredOn: 138 | print("Is Powered On.") 139 | startScanning() 140 | case .unsupported: 141 | print("Is Unsupported.") 142 | case .unauthorized: 143 | print("Is Unauthorized.") 144 | case .unknown: 145 | print("Unknown") 146 | case .resetting: 147 | print("Resetting") 148 | @unknown default: 149 | print("Error") 150 | } 151 | } 152 | 153 | // MARK: - Discover 154 | func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { 155 | print("Function: \(#function),Line: \(#line)") 156 | 157 | bluefruitPeripheral = peripheral 158 | 159 | if peripheralArray.contains(peripheral) { 160 | print("Duplicate Found.") 161 | } else { 162 | peripheralArray.append(peripheral) 163 | rssiArray.append(RSSI) 164 | } 165 | 166 | peripheralFoundLabel.text = "Peripherals Found: \(peripheralArray.count)" 167 | 168 | bluefruitPeripheral.delegate = self 169 | 170 | print("Peripheral Discovered: \(peripheral)") 171 | 172 | self.tableView.reloadData() 173 | } 174 | 175 | // MARK: - Connect 176 | func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { 177 | stopScanning() 178 | bluefruitPeripheral.discoverServices([CBUUIDs.BLEService_UUID]) 179 | } 180 | } 181 | 182 | // MARK: - CBPeripheralDelegate 183 | // A protocol that provides updates on the use of a peripheral’s services. 184 | extension ViewController: CBPeripheralDelegate { 185 | 186 | func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { 187 | 188 | guard let services = peripheral.services else { return } 189 | for service in services { 190 | peripheral.discoverCharacteristics(nil, for: service) 191 | } 192 | BlePeripheral.connectedService = services[0] 193 | } 194 | 195 | func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { 196 | 197 | guard let characteristics = service.characteristics else { 198 | return 199 | } 200 | 201 | print("Found \(characteristics.count) characteristics.") 202 | 203 | for characteristic in characteristics { 204 | 205 | if characteristic.uuid.isEqual(CBUUIDs.BLE_Characteristic_uuid_Rx) { 206 | 207 | rxCharacteristic = characteristic 208 | 209 | BlePeripheral.connectedRXChar = rxCharacteristic 210 | 211 | peripheral.setNotifyValue(true, for: rxCharacteristic!) 212 | peripheral.readValue(for: characteristic) 213 | 214 | print("RX Characteristic: \(rxCharacteristic.uuid)") 215 | } 216 | 217 | if characteristic.uuid.isEqual(CBUUIDs.BLE_Characteristic_uuid_Tx){ 218 | txCharacteristic = characteristic 219 | BlePeripheral.connectedTXChar = txCharacteristic 220 | print("TX Characteristic: \(txCharacteristic.uuid)") 221 | } 222 | } 223 | delayedConnection() 224 | } 225 | 226 | 227 | 228 | func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { 229 | 230 | var characteristicASCIIValue = NSString() 231 | 232 | guard characteristic == rxCharacteristic, 233 | 234 | let characteristicValue = characteristic.value, 235 | let ASCIIstring = NSString(data: characteristicValue, encoding: String.Encoding.utf8.rawValue) else { return } 236 | 237 | characteristicASCIIValue = ASCIIstring 238 | 239 | print("Value Recieved: \((characteristicASCIIValue as String))") 240 | 241 | NotificationCenter.default.post(name:NSNotification.Name(rawValue: "Notify"), object: "\((characteristicASCIIValue as String))") 242 | } 243 | 244 | func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) { 245 | peripheral.readRSSI() 246 | } 247 | 248 | func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) { 249 | guard error == nil else { 250 | print("Error discovering services: error") 251 | return 252 | } 253 | print("Function: \(#function),Line: \(#line)") 254 | print("Message sent") 255 | } 256 | 257 | 258 | func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) { 259 | print("*******************************************************") 260 | print("Function: \(#function),Line: \(#line)") 261 | if (error != nil) { 262 | print("Error changing notification state:\(String(describing: error?.localizedDescription))") 263 | 264 | } else { 265 | print("Characteristic's value subscribed") 266 | } 267 | 268 | if (characteristic.isNotifying) { 269 | print ("Subscribed. Notification has begun for: \(characteristic.uuid)") 270 | } 271 | } 272 | 273 | } 274 | 275 | // MARK: - UITableViewDataSource 276 | // The methods adopted by the object you use to manage data and provide cells for a table view. 277 | extension ViewController: UITableViewDataSource { 278 | 279 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 280 | return self.peripheralArray.count 281 | } 282 | 283 | 284 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 285 | 286 | let cell = tableView.dequeueReusableCell(withIdentifier: "BlueCell") as! TableViewCell 287 | 288 | let peripheralFound = self.peripheralArray[indexPath.row] 289 | 290 | let rssiFound = self.rssiArray[indexPath.row] 291 | 292 | if peripheralFound == nil { 293 | cell.peripheralLabel.text = "Unknown" 294 | }else { 295 | cell.peripheralLabel.text = peripheralFound.name 296 | cell.rssiLabel.text = "RSSI: \(rssiFound)" 297 | } 298 | return cell 299 | } 300 | 301 | 302 | } 303 | 304 | 305 | // MARK: - UITableViewDelegate 306 | // Methods for managing selections, deleting and reordering cells and performing other actions in a table view. 307 | extension ViewController: UITableViewDelegate { 308 | 309 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 310 | 311 | bluefruitPeripheral = peripheralArray[indexPath.row] 312 | 313 | BlePeripheral.connectedPeripheral = bluefruitPeripheral 314 | 315 | connectToDevice() 316 | 317 | } 318 | } 319 | 320 | -------------------------------------------------------------------------------- /Basic Chat MVC/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSBluetoothAlwaysUsageDescription 24 | Can this app use Bluetooth? 25 | NSBluetoothPeripheralUsageDescription 26 | Can this app communicate with Bluetooth peripherals? 27 | UIApplicationSceneManifest 28 | 29 | UIApplicationSupportsMultipleScenes 30 | 31 | UISceneConfigurations 32 | 33 | UIWindowSceneSessionRoleApplication 34 | 35 | 36 | UISceneConfigurationName 37 | Default Configuration 38 | UISceneDelegateClassName 39 | $(PRODUCT_MODULE_NAME).SceneDelegate 40 | UISceneStoryboardFile 41 | Main 42 | 43 | 44 | 45 | 46 | UIApplicationSupportsIndirectInputEvents 47 | 48 | UILaunchStoryboardName 49 | LaunchScreen 50 | UIMainStoryboardFile 51 | Main 52 | UIRequiredDeviceCapabilities 53 | 54 | armv7 55 | 56 | UISupportedInterfaceOrientations 57 | 58 | UIInterfaceOrientationPortrait 59 | 60 | UISupportedInterfaceOrientations~ipad 61 | 62 | UIInterfaceOrientationPortrait 63 | UIInterfaceOrientationPortraitUpsideDown 64 | UIInterfaceOrientationLandscapeLeft 65 | UIInterfaceOrientationLandscapeRight 66 | 67 | UIViewControllerBasedStatusBarAppearance 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Basic Chat MVC/Model/BlePeripheral.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BlePeripheral.swift 3 | // Basic Chat MVC 4 | // 5 | // Created by Trevor Beaton on 2/14/21. 6 | // 7 | 8 | import Foundation 9 | import CoreBluetooth 10 | 11 | class BlePeripheral { 12 | static var connectedPeripheral: CBPeripheral? 13 | static var connectedService: CBService? 14 | static var connectedTXChar: CBCharacteristic? 15 | static var connectedRXChar: CBCharacteristic? 16 | } 17 | -------------------------------------------------------------------------------- /Basic Chat MVC/Model/CBUUIDs.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CBUUIDs.swift 3 | // Basic Chat MVC 4 | // 5 | // Created by Trevor Beaton on 2/3/21. 6 | // 7 | 8 | import Foundation 9 | import CoreBluetooth 10 | 11 | struct CBUUIDs{ 12 | 13 | static let kBLEService_UUID = "6e400001-b5a3-f393-e0a9-e50e24dcca9e" 14 | static let kBLE_Characteristic_uuid_Tx = "6e400002-b5a3-f393-e0a9-e50e24dcca9e" 15 | static let kBLE_Characteristic_uuid_Rx = "6e400003-b5a3-f393-e0a9-e50e24dcca9e" 16 | static let MaxCharacters = 20 17 | 18 | static let BLEService_UUID = CBUUID(string: kBLEService_UUID) 19 | static let BLE_Characteristic_uuid_Tx = CBUUID(string: kBLE_Characteristic_uuid_Tx)//(Property = Write without response) 20 | static let BLE_Characteristic_uuid_Rx = CBUUID(string: kBLE_Characteristic_uuid_Rx)// (Property = Read/Notify) 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Basic Chat MVC/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // Basic Chat MVC 4 | // 5 | // Created by Trevor Beaton on 2/3/21. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Basic Chat MVC/View/TableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewCell.swift 3 | // Basic Chat MVC 4 | // 5 | // Created by Trevor Beaton on 2/4/21. 6 | // 7 | 8 | import UIKit 9 | 10 | class TableViewCell: UITableViewCell { 11 | 12 | @IBOutlet weak var peripheralLabel: UILabel! 13 | @IBOutlet weak var rssiLabel: UILabel! 14 | 15 | 16 | 17 | override func awakeFromNib() { 18 | super.awakeFromNib() 19 | // Initialization code 20 | } 21 | 22 | override func setSelected(_ selected: Bool, animated: Bool) { 23 | super.setSelected(selected, animated: animated) 24 | 25 | // Configure the view for the selected state 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Trevor Beaton for Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic-Chat 2 | Bluetooth Low Energy App for iOS using Swift 5 to communicate with another device that implements the Nordic UART Service. 3 | 4 | This sample project is the source for [this tutorial](https://learn.adafruit.com/crack-the-code/overview). It is not meant to cover product ready iOS development. It is only an introduction to BLE and iOS. 5 | --------------------------------------------------------------------------------