diff --git a/CoreNFCSampler.xcodeproj/project.pbxproj b/CoreNFCSampler.xcodeproj/project.pbxproj new file mode 100644 index 0000000..46e955e --- /dev/null +++ b/CoreNFCSampler.xcodeproj/project.pbxproj @@ -0,0 +1,367 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + DE3011EF2BD4BC29000F9277 /* CoreNFCSamplerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3011EE2BD4BC29000F9277 /* CoreNFCSamplerApp.swift */; }; + DE3011F12BD4BC29000F9277 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3011F02BD4BC29000F9277 /* ContentView.swift */; }; + DE3011F32BD4BC2B000F9277 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DE3011F22BD4BC2B000F9277 /* Assets.xcassets */; }; + DE3011F62BD4BC2B000F9277 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DE3011F52BD4BC2B000F9277 /* Preview Assets.xcassets */; }; + DE3011FF2BD4BD35000F9277 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3011FE2BD4BD35000F9277 /* Utility.swift */; }; + DE3012012BD4BD5C000F9277 /* NFCTagReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3012002BD4BD5C000F9277 /* NFCTagReader.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + DE3011EB2BD4BC29000F9277 /* CoreNFCSampler.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CoreNFCSampler.app; sourceTree = BUILT_PRODUCTS_DIR; }; + DE3011EE2BD4BC29000F9277 /* CoreNFCSamplerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreNFCSamplerApp.swift; sourceTree = ""; }; + DE3011F02BD4BC29000F9277 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + DE3011F22BD4BC2B000F9277 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + DE3011F52BD4BC2B000F9277 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + DE3011FC2BD4BCC1000F9277 /* CoreNFCSampler.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CoreNFCSampler.entitlements; sourceTree = ""; }; + DE3011FD2BD4BCD7000F9277 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + DE3011FE2BD4BD35000F9277 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = ""; }; + DE3012002BD4BD5C000F9277 /* NFCTagReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFCTagReader.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DE3011E82BD4BC29000F9277 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + DE3011E22BD4BC29000F9277 = { + isa = PBXGroup; + children = ( + DE3011ED2BD4BC29000F9277 /* CoreNFCSampler */, + DE3011EC2BD4BC29000F9277 /* Products */, + ); + sourceTree = ""; + }; + DE3011EC2BD4BC29000F9277 /* Products */ = { + isa = PBXGroup; + children = ( + DE3011EB2BD4BC29000F9277 /* CoreNFCSampler.app */, + ); + name = Products; + sourceTree = ""; + }; + DE3011ED2BD4BC29000F9277 /* CoreNFCSampler */ = { + isa = PBXGroup; + children = ( + DE3011FD2BD4BCD7000F9277 /* Info.plist */, + DE3011FC2BD4BCC1000F9277 /* CoreNFCSampler.entitlements */, + DE3011EE2BD4BC29000F9277 /* CoreNFCSamplerApp.swift */, + DE3012002BD4BD5C000F9277 /* NFCTagReader.swift */, + DE3011F02BD4BC29000F9277 /* ContentView.swift */, + DE3011FE2BD4BD35000F9277 /* Utility.swift */, + DE3011F22BD4BC2B000F9277 /* Assets.xcassets */, + DE3011F42BD4BC2B000F9277 /* Preview Content */, + ); + path = CoreNFCSampler; + sourceTree = ""; + }; + DE3011F42BD4BC2B000F9277 /* Preview Content */ = { + isa = PBXGroup; + children = ( + DE3011F52BD4BC2B000F9277 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + DE3011EA2BD4BC29000F9277 /* CoreNFCSampler */ = { + isa = PBXNativeTarget; + buildConfigurationList = DE3011F92BD4BC2B000F9277 /* Build configuration list for PBXNativeTarget "CoreNFCSampler" */; + buildPhases = ( + DE3011E72BD4BC29000F9277 /* Sources */, + DE3011E82BD4BC29000F9277 /* Frameworks */, + DE3011E92BD4BC29000F9277 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CoreNFCSampler; + productName = CoreNFCSampler; + productReference = DE3011EB2BD4BC29000F9277 /* CoreNFCSampler.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DE3011E32BD4BC29000F9277 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1530; + LastUpgradeCheck = 1530; + TargetAttributes = { + DE3011EA2BD4BC29000F9277 = { + CreatedOnToolsVersion = 15.3; + }; + }; + }; + buildConfigurationList = DE3011E62BD4BC29000F9277 /* Build configuration list for PBXProject "CoreNFCSampler" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = DE3011E22BD4BC29000F9277; + productRefGroup = DE3011EC2BD4BC29000F9277 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DE3011EA2BD4BC29000F9277 /* CoreNFCSampler */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DE3011E92BD4BC29000F9277 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DE3011F62BD4BC2B000F9277 /* Preview Assets.xcassets in Resources */, + DE3011F32BD4BC2B000F9277 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DE3011E72BD4BC29000F9277 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DE3011F12BD4BC29000F9277 /* ContentView.swift in Sources */, + DE3011EF2BD4BC29000F9277 /* CoreNFCSamplerApp.swift in Sources */, + DE3011FF2BD4BD35000F9277 /* Utility.swift in Sources */, + DE3012012BD4BD5C000F9277 /* NFCTagReader.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + DE3011F72BD4BC2B000F9277 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.4; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + DE3011F82BD4BC2B000F9277 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.4; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + DE3011FA2BD4BC2B000F9277 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = CoreNFCSampler/CoreNFCSampler.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"CoreNFCSampler/Preview Content\""; + DEVELOPMENT_TEAM = XX5J8N9TWW; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = CoreNFCSampler/Info.plist; + INFOPLIST_KEY_NFCReaderUsageDescription = "It's required for scaning nfc tags."; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.naoyamaeda.CoreNFCSampler; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + DE3011FB2BD4BC2B000F9277 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = CoreNFCSampler/CoreNFCSampler.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"CoreNFCSampler/Preview Content\""; + DEVELOPMENT_TEAM = XX5J8N9TWW; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = CoreNFCSampler/Info.plist; + INFOPLIST_KEY_NFCReaderUsageDescription = "It's required for scaning nfc tags."; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.naoyamaeda.CoreNFCSampler; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DE3011E62BD4BC29000F9277 /* Build configuration list for PBXProject "CoreNFCSampler" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DE3011F72BD4BC2B000F9277 /* Debug */, + DE3011F82BD4BC2B000F9277 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DE3011F92BD4BC2B000F9277 /* Build configuration list for PBXNativeTarget "CoreNFCSampler" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DE3011FA2BD4BC2B000F9277 /* Debug */, + DE3011FB2BD4BC2B000F9277 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = DE3011E32BD4BC29000F9277 /* Project object */; +} diff --git a/CoreNFCSampler.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/CoreNFCSampler.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/CoreNFCSampler.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/CoreNFCSampler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/CoreNFCSampler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/CoreNFCSampler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/CoreNFCSampler/Assets.xcassets/AccentColor.colorset/Contents.json b/CoreNFCSampler/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/CoreNFCSampler/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/CoreNFCSampler/Assets.xcassets/AppIcon.appiconset/Contents.json b/CoreNFCSampler/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/CoreNFCSampler/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/CoreNFCSampler/Assets.xcassets/Contents.json b/CoreNFCSampler/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/CoreNFCSampler/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/CoreNFCSampler/ContentView.swift b/CoreNFCSampler/ContentView.swift new file mode 100644 index 0000000..14a7798 --- /dev/null +++ b/CoreNFCSampler/ContentView.swift @@ -0,0 +1,69 @@ +// +// ContentView.swift +// +// +// Created by Naoya Maeda on 2024/04/21 +// +// + +import SwiftUI + +struct ContentView: View { + @StateObject private var reader = NFCTagReader() + @FocusState private var emailFieldIsFocused: Bool + + var body: some View { + VStack(spacing: 0) { + Text("Scan Result") + .font(.largeTitle) + Text(reader.readMessage ?? "") + Spacer() + if reader.sessionType == .write { + VStack(alignment: .leading) { + Text("Write Message") + TextField( + "Enter the message.", + text: $reader.writeMesage + ) + .focused($emailFieldIsFocused) + .textFieldStyle(RoundedBorderTextFieldStyle()) + } + .padding() + } + if reader.nfcFormat == .ndef { + Picker("Session Type", selection: $reader.sessionType) { + ForEach(SessionType.allCases) { session in + Text(session.rawValue).tag(session) + } + } + .colorMultiply(.accentColor) + .pickerStyle(.segmented) + .padding() + } + Picker("NFC Format", selection: $reader.nfcFormat) { + ForEach(NFCFormat.allCases) { session in + Text(session.rawValue).tag(session) + } + } + .colorMultiply(.accentColor) + .pickerStyle(.segmented) + .padding() + Button(action: { + reader.beginScanning() + }, label: { + Text("Scan") + .frame(width: 200, height: 15) + }) + .padding() + .accentColor(Color.white) + .background(Color.accentColor) + .cornerRadius(.infinity) + .disabled(!reader.readingAvailable) + } + .padding() + } +} + +#Preview { + ContentView() +} diff --git a/CoreNFCSampler/CoreNFCSampler.entitlements b/CoreNFCSampler/CoreNFCSampler.entitlements new file mode 100644 index 0000000..2bb4dee --- /dev/null +++ b/CoreNFCSampler/CoreNFCSampler.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.developer.nfc.readersession.formats + + TAG + + + diff --git a/CoreNFCSampler/CoreNFCSamplerApp.swift b/CoreNFCSampler/CoreNFCSamplerApp.swift new file mode 100644 index 0000000..733a707 --- /dev/null +++ b/CoreNFCSampler/CoreNFCSamplerApp.swift @@ -0,0 +1,18 @@ +// +// CoreNFCSamplerApp.swift +// +// +// Created by Naoya Maeda on 2024/04/21 +// +// + +import SwiftUI + +@main +struct CoreNFCSamplerApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/CoreNFCSampler/Info.plist b/CoreNFCSampler/Info.plist new file mode 100644 index 0000000..8b0a973 --- /dev/null +++ b/CoreNFCSampler/Info.plist @@ -0,0 +1,10 @@ + + + + + com.apple.developer.nfc.readersession.felica.systemcodes + + 0003 + + + diff --git a/CoreNFCSampler/NFCTagReader.swift b/CoreNFCSampler/NFCTagReader.swift new file mode 100644 index 0000000..fbefc47 --- /dev/null +++ b/CoreNFCSampler/NFCTagReader.swift @@ -0,0 +1,188 @@ +// +// NFCTagReader.swift +// +// +// Created by Naoya Maeda on 2024/04/21 +// +// + +import CoreNFC + +final class NFCTagReader: NSObject, ObservableObject { + private var session: NFCNDEFReaderSession? + private var tagSession: NFCTagReaderSession? + + var writeMesage = "CoreNFCTest" + let readingAvailable: Bool + + @Published var sessionType = SessionType.read + @Published var nfcFormat = NFCFormat.ndef + @Published var readMessage: String? + + override init() { + readingAvailable = NFCNDEFReaderSession.readingAvailable + } + + func beginScanning() { + guard readingAvailable else { + print("This iPhone is not NFC-enabled.") + return + } + + switch nfcFormat { + case .ndef: + session = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false) + session?.alertMessage = "Please bring your iPhone close to the NFC tag." + session?.begin() + + case .suica: + tagSession = NFCTagReaderSession(pollingOption: .iso18092, delegate: self, queue: nil) + tagSession?.alertMessage = "Please bring your iPhone close to the NFC tag." + tagSession?.begin() + } + } + + private func read(tag: NFCNDEFTag, session: NFCNDEFReaderSession) { + tag.readNDEF { [weak self] message, error in + session.alertMessage = "The tag reading has been completed." + session.invalidate() + if let message { + DispatchQueue.main.async { + self?.readMessage = self?.getStringFromNFCNDEF(message: message) + } + } + } + } + + private func getStringFromNFCNDEF(message: NFCNDEFMessage) -> String { + message.records.compactMap { + switch $0.typeNameFormat { + case .nfcWellKnown: + if let url = $0.wellKnownTypeURIPayload() { + return url.absoluteString + } + if let text = String(data: $0.payload, encoding: .utf8) { + return text + } + return nil + default: + return nil + } + }.joined(separator: "\n\n") + } +} + +extension NFCTagReader: NFCNDEFReaderSessionDelegate { + func readerSessionDidBecomeActive(_ session: NFCNDEFReaderSession) { + print("Reader session is active.") + } + + func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) { + print("error:\(error.localizedDescription)") + } + + /// readerSession(_:didDetect:)を実装すると呼び出されなくなる + func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) { + guard messages.count > 0 else { return } + + self.readMessage = getStringFromNFCNDEF(message: messages.first!) + session.alertMessage = "The tag reading has been completed." + session.invalidate() + } + + func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) { + guard tags.count < 2 else { return } + + let tag = tags.first! + session.connect(to: tag, completionHandler: { (error: Error?) in + guard error == nil else { + session.invalidate(errorMessage: "Unable to connect to tag.") + return + } + + tag.queryNDEFStatus(completionHandler: { [weak self] (ndefStatus: NFCNDEFStatus, capacity: Int, error: Error?) in + guard let self else { return } + + guard error == nil else { + session.invalidate(errorMessage: "Unable to query the NDEF status of tag.") + return + } + + switch ndefStatus { + case .notSupported: + session.invalidate(errorMessage: "Tag is not NDEF compliant.") + + case .readOnly: + guard sessionType == .read else { + session.invalidate(errorMessage: "Tag is read only.") + return + } + read(tag: tag, session: session) + + case .readWrite: + switch sessionType { + case .read: + read(tag: tag, session: session) + + case .write: + let data = writeMesage.data(using: .utf8)! + let payload = NFCNDEFPayload(format: .nfcWellKnown, type: Data("T".utf8), identifier: Data(), payload: data) + let message = NFCNDEFMessage(records: [payload]) + tag.writeNDEF(message, completionHandler: { (error: Error?) in + if nil != error { + session.invalidate(errorMessage: "Write NDEF message fail: \(error!)") + } else { + session.alertMessage = "Write NDEF message successful." + session.invalidate() + } + }) + case .lock: + session.alertMessage = "The tag locking has been completed." + session.invalidate() + } + + @unknown default: + session.alertMessage = "Unknown NDEF tag status." + session.invalidate() + } + }) + }) + } +} + +extension NFCTagReader: NFCTagReaderSessionDelegate { + func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) { + print("Reader session is active.") + } + + func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) { + print("error:\(error.localizedDescription)") + } + + func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) { + let tag = tags.first! + + session.connect(to: tag) { (error) in + if nil != error { + session.invalidate(errorMessage: "Unable to connect to tag.") + return + } + + guard case .feliCa(let feliCaTag) = tag else { + let retryInterval = DispatchTimeInterval.milliseconds(500) + session.alertMessage = "A tag that is not FeliCa is detected, please try again with tag FeliCa." + DispatchQueue.global().asyncAfter(deadline: .now() + retryInterval, execute: { + session.restartPolling() + }) + return + } + + let idm = feliCaTag.currentIDm.map { String(format: "%.2hhx", $0) }.joined() + DispatchQueue.main.async { [weak self] in + self?.readMessage = idm + } + session.alertMessage = "The tag reading has been completed." + session.invalidate() + } + } +} diff --git a/CoreNFCSampler/Preview Content/Preview Assets.xcassets/Contents.json b/CoreNFCSampler/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/CoreNFCSampler/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/CoreNFCSampler/Utility.swift b/CoreNFCSampler/Utility.swift new file mode 100644 index 0000000..e031a14 --- /dev/null +++ b/CoreNFCSampler/Utility.swift @@ -0,0 +1,22 @@ +// +// Utility.swift +// +// +// Created by Naoya Maeda on 2024/04/21 +// +// + +import Foundation + +enum SessionType: String, CaseIterable, Identifiable { + case read + case write + case lock + var id: String { rawValue } +} + +enum NFCFormat: String, CaseIterable, Identifiable { + case ndef + case suica + var id: String { rawValue } +}