Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Core NFC の新機能 / What's new in Core NFC (WWDC20)

Core NFC の新機能 / What's new in Core NFC (WWDC20)

集まれSwift好き!Swift愛好会スピンオフ WWDC20セッション要約会 @ Online で発表した LT「Core NFC の新機能」です。

More Decks by treastrain / Tanaka Ryoga

Other Decks in Programming

Transcript

  1. $PQZSJHIU˜USFBTUSBJO5BOBLB3ZPHBɹ"MMSJHIUTSFTFSWFE  USFBTUSBJO5BOBLB3ZPHB 4XJGU J04 XBUDI04 $PSF/'$ 044 ɹɹɹɹɹɹɹɹɹɹ!USFBTUSBJOɹIUUQTUSFUKQ 

    ߴઐʢʣ‎େֶʢʣ‎৽ଔʢʣ ੜ·Εͯ͸͡Ίͯຊ֨తʹऔΓ૊Μͩ ϓϩάϥϛϯάݴޠ4XJGU  ࣗݾ঺հ
  2. $PQZSJHIU˜USFBTUSBJO5BOBLB3ZPHBɹ"MMSJHIUTSFTFSWFE "QQ$MJQTͰ$PSF/'$͸࢖Θͳ͍ J04Ͱ࢖͑ΔίϯύΫτͳ"QQ w "QQ$MJQTΛ։͘ w /'$ w 23ίʔυ w

    Ϛοϓʢ෇ۙͷݕࡧʣ w 4JSJ͔ΒͷఏҊ w 4BGBSJ w ϝοηʔδ w "QQ$MJQίʔυ w /'$ɾ23ίʔυͷத਎͸ 6OJWFSTBM-JOLT w J04ଆ͕ಡΈऔͬͯॲཧ͢Δ ‎$PSF/'$ͷ࣮૷͸ඞཁͳ͠ 
  3. $PQZSJHIU˜USFBTUSBJO5BOBLB3ZPHBɹ"MMSJHIUTSFTFSWFE 3FTVMUΛ࢖ͬͨ4XJGUߏจ .PEFSO4XJGUTZOUBYXJUI3FTVMU w J04ҎલͷNFCFeliCaTagͷྫ &YBNQMFPGNFCFeliCaTagCFGPSFJ04  detectedFeliCaTag.readWithoutEncryption( serviceCodeList: serviceCodeList,

    blockList: blockList) { ( statusFlag1: Int, statusFlag2: Int, blockData: [Data], error: Error?) in if let error = error { // Handle error. return } // Handle status flag 1, status flag 2 and block data }
  4. $PQZSJHIU˜USFBTUSBJO5BOBLB3ZPHBɹ"MMSJHIUTSFTFSWFE 3FTVMUΛ࢖ͬͨ4XJGUߏจ .PEFSO4XJGUTZOUBYXJUI3FTVMU w J04Ҏ߱ͷNFCFeliCaTagͷྫ &YBNQMFPGNFCFeliCaTagBGUFSJ04  detectedFeliCaTag.readWithoutEncryption( serviceCodeList: serviceCodeList,

    blockList: blockList) { ( response: Result<(NFCFeliCaStatusFlag, [Data]), Error>) in switch response { case .success((let statusFlag, let blockData)): // Handle NFCFeliCaStatusFlag object and block data case .failure(let error): // Handle Error object. } }
  5. $PQZSJHIU˜USFBTUSBJO5BOBLB3ZPHBɹ"MMSJHIUTSFTFSWFE detectedFeliCaTag.readWithoutEncryption( serviceCodeList: serviceCodeList, blockList: blockList) { ( statusFlag1: Int,

    statusFlag2: Int, blockData: [Data], error: Error?) in if let error = error { session.invalidate(errorMessage: error.localizedDescription) } guard statusFlag1 == 0x00, statusFlag2 == 0x00 else { session.invalidate( errorMessage: "εςʔλεϑϥά͕ΤϥʔΛ͍ࣔͯ͠·͢ɻ\(statusFlag1), \(statusFlag2)") return } let data = blockData.first! let balance = Int(data[11]) + Int(data[12]) << 8 session.alertMessage = "࢒ߴ: ¥\(balance)" session.invalidate() } ަ௨ܥ*$Χʔυͷ࢒ߴΛಡΈऔΔ J04Ҏલͷ৔߹ɹcompletionHandler 
  6. $PQZSJHIU˜USFBTUSBJO5BOBLB3ZPHBɹ"MMSJHIUTSFTFSWFE detectedFeliCaTag.readWithoutEncryption( serviceCodeList: serviceCodeList, blockList: blockList) { ( response: Result<(NFCFeliCaStatusFlag,

    [Data]), Error>) in switch response { case .success((let statusFlag, let blockData)): guard statusFlag.statusFlag1 == 0x00, statusFlag.statusFlag2 == 0x00 else { session.invalidate(errorMessage: "εςʔλεϑϥά͕ΤϥʔΛ͍ࣔͯ͠·͢ɻ\(statusFlag)") return } let data = blockData.first! let balance = Int(data[11]) + Int(data[12]) << 8 session.alertMessage = "࢒ߴ: ¥\(balance)" session.invalidate() case .failure(let error): session.invalidate(errorMessage: error.localizedDescription) } } ަ௨ܥ*$Χʔυͷ࢒ߴΛಡΈऔΔ J04Ҏલͷ৔߹ɹresultHandler