Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
1998code committed Jan 10, 2023
0 parents commit f09b0f5
Show file tree
Hide file tree
Showing 17 changed files with 879 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
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
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>
397 changes: 397 additions & 0 deletions Demo/NFC Read-Write.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>
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
}
}
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
}
}
6 changes: 6 additions & 0 deletions Demo/NFC Read-Write/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
105 changes: 105 additions & 0 deletions Demo/NFC Read-Write/ContentView.swift
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()
}
}
14 changes: 14 additions & 0 deletions Demo/NFC Read-Write/NFC_Read_Write.entitlements
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>
39 changes: 39 additions & 0 deletions Demo/NFC Read-Write/NFC_Read_WriteApp.swift
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions Demo/NFC-Read-Write-Info.plist
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>
26 changes: 26 additions & 0 deletions Package.swift
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: [])
]
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SwiftNFC - Powerful Read+Write in few lines of Coding
Loading

0 comments on commit f09b0f5

Please sign in to comment.