├── .gitignore ├── LICENSE ├── README.md ├── TagReader.xcodeproj └── project.pbxproj ├── TagReader ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── NFCHelper.swift ├── TagReader.entitlements └── ViewController.swift └── art ├── image1.png └── image2.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/xcode 2 | # Edit at https://www.gitignore.io/?templates=xcode 3 | 4 | ### Xcode ### 5 | # Xcode 6 | # 7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 8 | 9 | ## User settings 10 | xcuserdata/ 11 | 12 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 13 | *.xcscmblueprint 14 | *.xccheckout 15 | 16 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 17 | build/ 18 | DerivedData/ 19 | *.moved-aside 20 | *.pbxuser 21 | !default.pbxuser 22 | *.mode1v3 23 | !default.mode1v3 24 | *.mode2v3 25 | !default.mode2v3 26 | *.perspectivev3 27 | !default.perspectivev3 28 | 29 | ### Xcode Patch ### 30 | *.xcodeproj/* 31 | !*.xcodeproj/project.pbxproj 32 | !*.xcodeproj/xcshareddata/ 33 | !*.xcworkspace/contents.xcworkspacedata 34 | /*.gcno 35 | **/xcshareddata/WorkspaceSettings.xcsettings 36 | 37 | # End of https://www.gitignore.io/api/xcode -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Qifan Yang 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | This project is just read NFC tag by using ios coreNFC, it's a helper project for [cardEmulation](https://github.com/underwindfall/NFCAndroid) to verify Android card emulation is correct to be done or not. 4 | 5 | 6 | ## ScreenShot 7 | ### Reader 8 | 9 | 10 | 11 | ## Ref 12 | https://developer.apple.com/documentation/corenfc 13 | https://developer.apple.com/documentation/corenfc/nfctypenameformat 14 | 15 | -------------------------------------------------------------------------------- /TagReader.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 023108611EF4C0D600091E95 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023108601EF4C0D600091E95 /* AppDelegate.swift */; }; 11 | 023108631EF4C0D600091E95 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023108621EF4C0D600091E95 /* ViewController.swift */; }; 12 | 023108661EF4C0D600091E95 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 023108641EF4C0D600091E95 /* Main.storyboard */; }; 13 | 023108681EF4C0D600091E95 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 023108671EF4C0D600091E95 /* Assets.xcassets */; }; 14 | 0231086B1EF4C0D600091E95 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 023108691EF4C0D600091E95 /* LaunchScreen.storyboard */; }; 15 | 023108731EF4C1A400091E95 /* NFCHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023108721EF4C1A400091E95 /* NFCHelper.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 0231085D1EF4C0D600091E95 /* TagReader.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TagReader.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 023108601EF4C0D600091E95 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 023108621EF4C0D600091E95 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 023108651EF4C0D600091E95 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 023108671EF4C0D600091E95 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 0231086A1EF4C0D600091E95 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | 0231086C1EF4C0D600091E95 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 023108721EF4C1A400091E95 /* NFCHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFCHelper.swift; sourceTree = ""; }; 27 | AC40B5E121AC478D00698C5B /* TagReader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TagReader.entitlements; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | 0231085A1EF4C0D600091E95 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 023108541EF4C0D600091E95 = { 42 | isa = PBXGroup; 43 | children = ( 44 | 0231085F1EF4C0D600091E95 /* TagReader */, 45 | 0231085E1EF4C0D600091E95 /* Products */, 46 | 02CE282D1EF4C40E002ADE8E /* Frameworks */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 0231085E1EF4C0D600091E95 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 0231085D1EF4C0D600091E95 /* TagReader.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 0231085F1EF4C0D600091E95 /* TagReader */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | AC40B5E121AC478D00698C5B /* TagReader.entitlements */, 62 | 023108601EF4C0D600091E95 /* AppDelegate.swift */, 63 | 023108621EF4C0D600091E95 /* ViewController.swift */, 64 | 023108641EF4C0D600091E95 /* Main.storyboard */, 65 | 023108671EF4C0D600091E95 /* Assets.xcassets */, 66 | 023108691EF4C0D600091E95 /* LaunchScreen.storyboard */, 67 | 0231086C1EF4C0D600091E95 /* Info.plist */, 68 | 023108721EF4C1A400091E95 /* NFCHelper.swift */, 69 | ); 70 | path = TagReader; 71 | sourceTree = ""; 72 | }; 73 | 02CE282D1EF4C40E002ADE8E /* Frameworks */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | ); 77 | name = Frameworks; 78 | sourceTree = ""; 79 | }; 80 | /* End PBXGroup section */ 81 | 82 | /* Begin PBXNativeTarget section */ 83 | 0231085C1EF4C0D600091E95 /* TagReader */ = { 84 | isa = PBXNativeTarget; 85 | buildConfigurationList = 0231086F1EF4C0D600091E95 /* Build configuration list for PBXNativeTarget "TagReader" */; 86 | buildPhases = ( 87 | 023108591EF4C0D600091E95 /* Sources */, 88 | 0231085A1EF4C0D600091E95 /* Frameworks */, 89 | 0231085B1EF4C0D600091E95 /* Resources */, 90 | ); 91 | buildRules = ( 92 | ); 93 | dependencies = ( 94 | ); 95 | name = TagReader; 96 | productName = TagReader; 97 | productReference = 0231085D1EF4C0D600091E95 /* TagReader.app */; 98 | productType = "com.apple.product-type.application"; 99 | }; 100 | /* End PBXNativeTarget section */ 101 | 102 | /* Begin PBXProject section */ 103 | 023108551EF4C0D600091E95 /* Project object */ = { 104 | isa = PBXProject; 105 | attributes = { 106 | LastSwiftUpdateCheck = 0900; 107 | LastUpgradeCheck = 0900; 108 | ORGANIZATIONNAME = "Jameson Quave"; 109 | TargetAttributes = { 110 | 0231085C1EF4C0D600091E95 = { 111 | CreatedOnToolsVersion = 9.0; 112 | ProvisioningStyle = Automatic; 113 | SystemCapabilities = { 114 | com.apple.ApplicationGroups.iOS = { 115 | enabled = 0; 116 | }; 117 | com.apple.GameCenter = { 118 | enabled = 0; 119 | }; 120 | com.apple.NearFieldCommunicationTagReading = { 121 | enabled = 1; 122 | }; 123 | }; 124 | }; 125 | }; 126 | }; 127 | buildConfigurationList = 023108581EF4C0D600091E95 /* Build configuration list for PBXProject "TagReader" */; 128 | compatibilityVersion = "Xcode 8.0"; 129 | developmentRegion = en; 130 | hasScannedForEncodings = 0; 131 | knownRegions = ( 132 | en, 133 | Base, 134 | ); 135 | mainGroup = 023108541EF4C0D600091E95; 136 | productRefGroup = 0231085E1EF4C0D600091E95 /* Products */; 137 | projectDirPath = ""; 138 | projectRoot = ""; 139 | targets = ( 140 | 0231085C1EF4C0D600091E95 /* TagReader */, 141 | ); 142 | }; 143 | /* End PBXProject section */ 144 | 145 | /* Begin PBXResourcesBuildPhase section */ 146 | 0231085B1EF4C0D600091E95 /* Resources */ = { 147 | isa = PBXResourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 0231086B1EF4C0D600091E95 /* LaunchScreen.storyboard in Resources */, 151 | 023108681EF4C0D600091E95 /* Assets.xcassets in Resources */, 152 | 023108661EF4C0D600091E95 /* Main.storyboard in Resources */, 153 | ); 154 | runOnlyForDeploymentPostprocessing = 0; 155 | }; 156 | /* End PBXResourcesBuildPhase section */ 157 | 158 | /* Begin PBXSourcesBuildPhase section */ 159 | 023108591EF4C0D600091E95 /* Sources */ = { 160 | isa = PBXSourcesBuildPhase; 161 | buildActionMask = 2147483647; 162 | files = ( 163 | 023108631EF4C0D600091E95 /* ViewController.swift in Sources */, 164 | 023108731EF4C1A400091E95 /* NFCHelper.swift in Sources */, 165 | 023108611EF4C0D600091E95 /* AppDelegate.swift in Sources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXSourcesBuildPhase section */ 170 | 171 | /* Begin PBXVariantGroup section */ 172 | 023108641EF4C0D600091E95 /* Main.storyboard */ = { 173 | isa = PBXVariantGroup; 174 | children = ( 175 | 023108651EF4C0D600091E95 /* Base */, 176 | ); 177 | name = Main.storyboard; 178 | sourceTree = ""; 179 | }; 180 | 023108691EF4C0D600091E95 /* LaunchScreen.storyboard */ = { 181 | isa = PBXVariantGroup; 182 | children = ( 183 | 0231086A1EF4C0D600091E95 /* Base */, 184 | ); 185 | name = LaunchScreen.storyboard; 186 | sourceTree = ""; 187 | }; 188 | /* End PBXVariantGroup section */ 189 | 190 | /* Begin XCBuildConfiguration section */ 191 | 0231086D1EF4C0D600091E95 /* Debug */ = { 192 | isa = XCBuildConfiguration; 193 | buildSettings = { 194 | ALWAYS_SEARCH_USER_PATHS = NO; 195 | CLANG_ANALYZER_NONNULL = YES; 196 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 197 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 198 | CLANG_CXX_LIBRARY = "libc++"; 199 | CLANG_ENABLE_MODULES = YES; 200 | CLANG_ENABLE_OBJC_ARC = YES; 201 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_COMMA = YES; 204 | CLANG_WARN_CONSTANT_CONVERSION = YES; 205 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 206 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 207 | CLANG_WARN_EMPTY_BODY = YES; 208 | CLANG_WARN_ENUM_CONVERSION = YES; 209 | CLANG_WARN_INFINITE_RECURSION = YES; 210 | CLANG_WARN_INT_CONVERSION = YES; 211 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 212 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 213 | CLANG_WARN_STRICT_PROTOTYPES = YES; 214 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 215 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 216 | CLANG_WARN_UNREACHABLE_CODE = YES; 217 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 218 | CODE_SIGN_IDENTITY = "iPhone Developer"; 219 | COPY_PHASE_STRIP = NO; 220 | DEBUG_INFORMATION_FORMAT = dwarf; 221 | ENABLE_STRICT_OBJC_MSGSEND = YES; 222 | ENABLE_TESTABILITY = YES; 223 | GCC_C_LANGUAGE_STANDARD = gnu11; 224 | GCC_DYNAMIC_NO_PIC = NO; 225 | GCC_NO_COMMON_BLOCKS = YES; 226 | GCC_OPTIMIZATION_LEVEL = 0; 227 | GCC_PREPROCESSOR_DEFINITIONS = ( 228 | "DEBUG=1", 229 | "$(inherited)", 230 | ); 231 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 232 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 233 | GCC_WARN_UNDECLARED_SELECTOR = YES; 234 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 235 | GCC_WARN_UNUSED_FUNCTION = YES; 236 | GCC_WARN_UNUSED_VARIABLE = YES; 237 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 238 | MTL_ENABLE_DEBUG_INFO = YES; 239 | ONLY_ACTIVE_ARCH = YES; 240 | SDKROOT = iphoneos; 241 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 242 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 243 | }; 244 | name = Debug; 245 | }; 246 | 0231086E1EF4C0D600091E95 /* Release */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_ANALYZER_NONNULL = YES; 251 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 252 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 253 | CLANG_CXX_LIBRARY = "libc++"; 254 | CLANG_ENABLE_MODULES = YES; 255 | CLANG_ENABLE_OBJC_ARC = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 261 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INFINITE_RECURSION = YES; 265 | CLANG_WARN_INT_CONVERSION = YES; 266 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 267 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 268 | CLANG_WARN_STRICT_PROTOTYPES = YES; 269 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 270 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | CODE_SIGN_IDENTITY = "iPhone Developer"; 274 | COPY_PHASE_STRIP = NO; 275 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 276 | ENABLE_NS_ASSERTIONS = NO; 277 | ENABLE_STRICT_OBJC_MSGSEND = YES; 278 | GCC_C_LANGUAGE_STANDARD = gnu11; 279 | GCC_NO_COMMON_BLOCKS = YES; 280 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 281 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 282 | GCC_WARN_UNDECLARED_SELECTOR = YES; 283 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 284 | GCC_WARN_UNUSED_FUNCTION = YES; 285 | GCC_WARN_UNUSED_VARIABLE = YES; 286 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 287 | MTL_ENABLE_DEBUG_INFO = NO; 288 | SDKROOT = iphoneos; 289 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 290 | VALIDATE_PRODUCT = YES; 291 | }; 292 | name = Release; 293 | }; 294 | 023108701EF4C0D600091E95 /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 298 | CODE_SIGN_ENTITLEMENTS = TagReader/TagReader.entitlements; 299 | CODE_SIGN_IDENTITY = "iPhone Developer"; 300 | CODE_SIGN_STYLE = Automatic; 301 | DEVELOPMENT_TEAM = C35G5EW7P5; 302 | INFOPLIST_FILE = TagReader/Info.plist; 303 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 304 | PRODUCT_BUNDLE_IDENTIFIER = com.carrefourbank.test.nfc; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | PROVISIONING_PROFILE_SPECIFIER = ""; 307 | SWIFT_VERSION = 4.0; 308 | TARGETED_DEVICE_FAMILY = "1,2"; 309 | }; 310 | name = Debug; 311 | }; 312 | 023108711EF4C0D600091E95 /* Release */ = { 313 | isa = XCBuildConfiguration; 314 | buildSettings = { 315 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 316 | CODE_SIGN_ENTITLEMENTS = TagReader/TagReader.entitlements; 317 | CODE_SIGN_IDENTITY = "iPhone Developer"; 318 | CODE_SIGN_STYLE = Automatic; 319 | DEVELOPMENT_TEAM = C35G5EW7P5; 320 | INFOPLIST_FILE = TagReader/Info.plist; 321 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 322 | PRODUCT_BUNDLE_IDENTIFIER = com.carrefourbank.test.nfc; 323 | PRODUCT_NAME = "$(TARGET_NAME)"; 324 | PROVISIONING_PROFILE_SPECIFIER = ""; 325 | SWIFT_VERSION = 4.0; 326 | TARGETED_DEVICE_FAMILY = "1,2"; 327 | }; 328 | name = Release; 329 | }; 330 | /* End XCBuildConfiguration section */ 331 | 332 | /* Begin XCConfigurationList section */ 333 | 023108581EF4C0D600091E95 /* Build configuration list for PBXProject "TagReader" */ = { 334 | isa = XCConfigurationList; 335 | buildConfigurations = ( 336 | 0231086D1EF4C0D600091E95 /* Debug */, 337 | 0231086E1EF4C0D600091E95 /* Release */, 338 | ); 339 | defaultConfigurationIsVisible = 0; 340 | defaultConfigurationName = Release; 341 | }; 342 | 0231086F1EF4C0D600091E95 /* Build configuration list for PBXNativeTarget "TagReader" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 023108701EF4C0D600091E95 /* Debug */, 346 | 023108711EF4C0D600091E95 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | /* End XCConfigurationList section */ 352 | }; 353 | rootObject = 023108551EF4C0D600091E95 /* Project object */; 354 | } 355 | -------------------------------------------------------------------------------- /TagReader/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | 6 | var window: UIWindow? 7 | 8 | 9 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 10 | // Override point for customization after application launch. 11 | return true 12 | } 13 | 14 | func applicationWillResignActive(_ application: UIApplication) { 15 | // 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. 16 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 17 | } 18 | 19 | func applicationDidEnterBackground(_ application: UIApplication) { 20 | // 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. 21 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 22 | } 23 | 24 | func applicationWillEnterForeground(_ application: UIApplication) { 25 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 26 | } 27 | 28 | func applicationDidBecomeActive(_ application: UIApplication) { 29 | // 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. 30 | } 31 | 32 | func applicationWillTerminate(_ application: UIApplication) { 33 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 34 | } 35 | 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /TagReader/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /TagReader/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 | -------------------------------------------------------------------------------- /TagReader/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 | -------------------------------------------------------------------------------- /TagReader/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | NFCReader 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NFCReaderUsageDescription 26 | To Detect Tags 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /TagReader/NFCHelper.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import CoreNFC 3 | 4 | class NFCHelper: NSObject, NFCNDEFReaderSessionDelegate { 5 | var onNFCResult: ((Bool, String) -> ())? 6 | func restartSession() { 7 | let session = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false) 8 | session.begin() 9 | } 10 | 11 | // MARK: NFCNDEFReaderSessionDelegate 12 | func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) { 13 | guard let onNFCResult = onNFCResult else { return } 14 | onNFCResult(false, error.localizedDescription) 15 | } 16 | 17 | func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) { 18 | guard let onNFCResult = onNFCResult else { return } 19 | 20 | print("Detected NDEF") 21 | var payload = "" 22 | for message in messages { 23 | for record in message.records { 24 | print(record.identifier) 25 | print(record.payload) 26 | print(record.type) 27 | print(record.typeNameFormat) 28 | 29 | payload += "\(record.identifier)\n" 30 | payload += "\(record.payload)\n" 31 | payload += "\(record.type)\n" 32 | payload += "\(record.typeNameFormat)\n" 33 | 34 | 35 | if let resultString = String(data: record.payload, encoding: .utf8) { 36 | onNFCResult(true, resultString) 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /TagReader/TagReader.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.nfc.readersession.formats 6 | 7 | NDEF 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TagReader/ViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ViewController: UIViewController { 4 | 5 | let helper = NFCHelper() 6 | var payloadLabel: UILabel! 7 | 8 | override func viewDidLoad() { 9 | super.viewDidLoad() 10 | 11 | let button = UIButton(type: .system) 12 | button.setTitle("Read NFC", for: .normal) 13 | button.titleLabel?.font = UIFont(name: "Helvetica", size: 28.0) 14 | button.addTarget(self, action: #selector(didTapReadNFC), for: .touchUpInside) 15 | button.frame = CGRect(x: 60, y: 200, width: self.view.bounds.width - 120, height: 80) 16 | self.view.addSubview(button) 17 | 18 | payloadLabel = UILabel(frame: button.frame.offsetBy(dx: 0, dy: 300)) 19 | payloadLabel.numberOfLines = 10 20 | payloadLabel.text = "Scan an NFC Tag" 21 | self.view.addSubview(payloadLabel) 22 | } 23 | 24 | func onNFCResult(success: Bool, msg: String) { 25 | DispatchQueue.main.async { 26 | self.payloadLabel.text = "\(self.payloadLabel.text!)\n\(msg)" 27 | } 28 | } 29 | 30 | @objc func didTapReadNFC() { 31 | print("didTapReadNFC") 32 | self.payloadLabel.text = "" 33 | helper.onNFCResult = onNFCResult(success:msg:) 34 | helper.restartSession() 35 | } 36 | 37 | override func didReceiveMemoryWarning() { 38 | super.didReceiveMemoryWarning() 39 | // Dispose of any resources that can be recreated. 40 | } 41 | 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /art/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underwindfall/NFCReaderiOS/760a6749960cd5faf5465e9661349d06da7f564d/art/image1.png -------------------------------------------------------------------------------- /art/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underwindfall/NFCReaderiOS/760a6749960cd5faf5465e9661349d06da7f564d/art/image2.png --------------------------------------------------------------------------------