-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f09b0f5
Showing
17 changed files
with
879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Demo/NFC Read-Write.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Demo/NFC Read-Write.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
38 changes: 38 additions & 0 deletions
38
Demo/NFC Read-Write/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "display-p3", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0.292", | ||
"green" : "0.342", | ||
"red" : "0.136" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"color" : { | ||
"color-space" : "display-p3", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0.432", | ||
"green" : "0.845", | ||
"red" : "0.136" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
Demo/NFC Read-Write/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// ContentView.swift | ||
// NFC Read-Write | ||
// | ||
// Created by Ming on 1/1/2023. | ||
// | ||
|
||
import SwiftUI | ||
import SwiftNFC | ||
|
||
struct ContentView: View { | ||
@ObservedObject var NFCR = NFCReader() | ||
@ObservedObject var NFCW = NFCWriter() | ||
|
||
var editor: some View { | ||
TextEditor(text: $NFCR.msg) | ||
.font(.title) | ||
.padding(.top, 50) | ||
.padding(15) | ||
.background(Color.accentColor.opacity(0.5)) | ||
} | ||
var editorRaw: some View { | ||
TextEditor(text: $NFCR.raw) | ||
.padding(15) | ||
.background(Color.red.opacity(0.5)) | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: 0) { | ||
VStack(spacing: 0) { | ||
if #available(iOS 16.0, *) { | ||
editor | ||
.scrollContentBackground(.hidden) | ||
option | ||
editorRaw | ||
.scrollContentBackground(.hidden) | ||
} else { | ||
// Fallback on earlier versions | ||
editor | ||
option | ||
editorRaw | ||
} | ||
} | ||
action | ||
.frame(height: 75) | ||
} | ||
.ignoresSafeArea(.all) | ||
.onTapGesture(count: 2) { | ||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) | ||
} | ||
} | ||
|
||
var option: some View { | ||
HStack { | ||
Picker(selection: $NFCW.type, label: Text("Type Picker")) { | ||
Text("Text").tag("T") | ||
Text("Link").tag("U") | ||
} | ||
Spacer() | ||
Button(action: { | ||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) | ||
}) { | ||
Text("Close Keyboard") | ||
} | ||
}.padding(.horizontal) | ||
} | ||
|
||
var action: some View { | ||
HStack(spacing: 0) { | ||
Button (action: { read() }) { | ||
ZStack { | ||
Color.blue.opacity(0.85) | ||
Label("Read NFC", systemImage: "wave.3.left.circle.fill") | ||
.foregroundColor(.white) | ||
.padding(.top, 15) | ||
.padding(.bottom, 35) | ||
} | ||
} | ||
Button (action: { write() }) { | ||
ZStack { | ||
Color.accentColor.opacity(0.85) | ||
Label("Write NFC", systemImage: "wave.3.left.circle.fill") | ||
.foregroundColor(.white) | ||
.padding(.top, 15) | ||
.padding(.bottom, 35) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func read() { | ||
NFCR.read() | ||
} | ||
|
||
func write() { | ||
NFCW.msg = NFCR.msg | ||
NFCW.write() | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.nfc.readersession.formats</key> | ||
<array> | ||
<string>TAG</string> | ||
</array> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// NFC_Read_WriteApp.swift | ||
// NFC Read-Write | ||
// | ||
// Created by Ming on 1/1/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct NFC_Read_WriteApp: App { | ||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} | ||
|
||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
var window: UIWindow? | ||
|
||
func application(_ application: UIApplication, | ||
continue userActivity: NSUserActivity, | ||
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { | ||
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else { | ||
return false | ||
} | ||
|
||
// Confirm that the NSUserActivity object contains a valid NDEF message. | ||
let ndefMessage = userActivity.ndefMessagePayload | ||
guard !ndefMessage.records.isEmpty, | ||
ndefMessage.records[0].typeNameFormat != .empty else { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Demo/NFC Read-Write/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>UIBackgroundModes</key> | ||
<array> | ||
<string>nearby-interaction</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swift-tools-version: 5.4 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
// | ||
// Created by Ming on 9/1/2023. | ||
// | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SwiftNFC", | ||
platforms: [ | ||
.iOS(.v13) | ||
], | ||
products: [ | ||
.library( | ||
name: "SwiftNFC", | ||
targets: ["SwiftNFC"]), | ||
], | ||
dependencies: [ | ||
], | ||
targets: [ | ||
.target( | ||
name: "SwiftNFC", | ||
dependencies: []) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# SwiftNFC - Powerful Read+Write in few lines of Coding |
Oops, something went wrong.