iOS 14からのアプリ内課金

iOS 14からのアプリ内課金

#potatotips #71での発表資料です。
https://potatotips.connpass.com/event/189012/

より詳しい内容はこちら
https://zenn.dev/tattn/books/ios14-in-app-purchase

おすすめ: iOS 14対応で気をつけるべきこと
https://zenn.dev/tattn/articles/40d1e53cc63d381a3ac5

Twitter: https://twitter.com/tanakasan2525

0620564f0125b8b3b7f4fe40c10b8b4e?s=128

Tatsuya Tanaka

October 23, 2020
Tweet

Transcript

  1. iOS 14͔Βͷ՝࣮ۚ૷ ాதୡ໵ (@tattn) #potatotips (#71)

  2. ాத ୡ໵ / ͨͳͨͭ (@tattn) • Yahoo!ΧʔφϏ • Yahoo!৐׵Ҋ಺ •

    શࣾԣஅνʔϜ @tattn @tanakasan2525 @tattn
  3. iOS 14ରԠͷهࣄॻ͖·ͨ͠ IUUQT[FOOEFWUBUUOBSUJDMFT EFDDEBBD

  4. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘

  5. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘ Xcode 12/iOS 14Ͱ͸ େ෯ʹվળ͠·ͨ͠

  6. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘

  7. StoreKit Configuration Xcode 12ʹStorekit Configurationͱ͍͏ػೳ͕ೖΓɺ App Storeͱ઀ଓͤͣʹ঎඼ͷऔಘ΍՝ۚͳͲ͕ςετͰ͖ΔΑ͏ʹ →SimulatorͰ΋՝ۚॲཧ͕ࢼͤΔΑ͏ʹ

  8. StoreKit Configurationͷ༗ޮԽ Edit Scheme͔Β࢖༻͢ΔઃఆΛબͿ

  9. ঎඼ͷઃఆ App Store ConnectͰઃఆ͢Δͷͱ΄΅ಉ͡಺༰Ͱ αϒεΫϦϓγϣϯ΍ফ໣ܕ/ඇফ໣ܕͷ঎඼ઃఆ͕Ͱ͖Δ

  10. γϛϡϨʔλͰ΋՝ۚՄೳʹ let payment = SKPayment(product: product) SKPaymentQueue.default().add(payment) ޙ͸StoreKitͰߪೖॲཧΛ࣮૷͢Δͱ γϛϡϨʔλͰ΋OSͷߪೖγʔτ͕දࣔ͞Εɺ ՝ۚͷςετ͕Ͱ͖Δ

  11. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘

  12. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘

  13. ΞϓϦ֎͔Βͷ՝ۚͷςετ

  14. αϒεΫϦϓγϣϯͷߪಡ͸ΞϓϦ֎͔Β΋Ͱ͖Δ Ұ౓ߪಡͨ͠αϒεΫϦϓγϣϯ͸ ઃఆΞϓϦ౳͔Β࠶ߪಡͰ͖Δ IUUQTTVQQPSUBQQMFDPNKBKQ)5

  15. iOS 14͔ΒSandbox؀ڥͰαϒεΫϦϓγϣϯͷ؅ཧ͕Մೳʹ ઃఆΞϓϦΛ։͘ App Store SandboxΞΧ΢ϯτʮApple ID: ***ʯ ؅ཧ

  16. Ask To Buy

  17. Ask To Buy (ঝೝͱߪೖͷϦΫΤετ) ࢠڙ͕՝ۚΞΠςϜΛߪೖ͢ΔλΠϛϯάͰ਌ʹ௨஌Λඈ͹͠ɺ ঝೝ͞ΕΔ·ͰߪೖΛ஗Ԇͤ͞Δػೳ .deferred .purchased SKPaymentTransaction ঝೝ

    IUUQTTVQQPSUBQQMFDPNKBKQ)5
  18. ࠓ·Ͱ͸ຊ൪ͷΑ͏ͳ஗Ԇߪೖ͕Ͱ͖ͳ͔ͬͨ simulatesAskToBuyInSandboxͱ͍͏ϓϩύςΟΛtrueʹ͢Δͱ ߪೖ࣌ʹঝೝΞϥʔτ͸ग़Δ͕ɺͦͷޙͷߪೖ͕Ͱ͖ͳ͔ͬͨ .deferred .purchased SKPaymentTransaction ݺ͹Εͳ͍ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOTUPSFLJUTLQBZNFOUTJNVMBUFTBTLUPCVZJOTBOECPY

  19. Xcode؀ڥͰͷAsk To Buyͷςετ Xcodeͷσόοά࣮ߦ؀ڥͳΒ τϥϯβΫγϣϯͷ؅ཧը໘Ͱঝೝorඇঝೝͷૢ࡞͕Մೳʹ .deferred .purchased SKPaymentTransaction Λԡ͢

  20. Manage StoreKit Transactions XcodeʹτϥϯβΫγϣϯͷ؅ཧը໘͕௥Ճ ߪೖཤྺͷ࡟আɺฦۚɺ՝ۚͷதஅͳͲ΋σόοά͕Մೳʹ

  21. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘

  22. ͜Ε·Ͱͷ՝࣮ۚ૷Ͱؾʹͳ͍ͬͯͨ఺ ࣮ػ͕ඞཁ ಈ࡞֬ೝ͕ ΍Γʹ͍͘ Ϣχοτςετ ΍Γʹ͍͘

  23. StoreKitTest StoreKitͷΫϥεΛϞοΫԽ͠ͳͯ͘΋ StoreKitͷಈ࡞ΛมߋͰ͖ΔStoreKitTestϑϨʔϜϫʔΫ͕ొ৔ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOTUPSFLJUUFTU

  24. Ϣχοτςετͷ४උ import XCTest import StoreKitTest override func setUpWithError() throws {

    // ςετ؀ڥΛ࡞੒ (.storekitϑΝΠϧͷಡΈࠐΈ) session = try SKTestSession(configurationFileNamed: "Configuration") // ՝ۚγʔτͳͲΛදࣔ͠ͳ͍Α͏ʹ͢Δ session.disableDialogs = true // ઃఆΛॳظԽ͢Δ session.resetToDefaultState() // τϥϯβΫγϣϯΛϦηοτ͢Δ session.clearTransactions() } μΠΞϩά΍OSͷ՝ۚγʔτͳͲΛඇදࣔʹͨ͠Γɺ ՝ۚཤྺΛϦηοτͨ͠ΓͰ͖Δ
  25. ߪೖࣦഊͷςετ func testFailed() throws { // ߪೖΛࣦഊͤ͞Δ session.failTransactionsEnabled = true

    session.failureError = .invalidSignature // ߪೖ try session.buyProduct(productIdentifier: ProductId.premium.rawValue) XCTAssertEqual(session.allTransactions()[0].state, .failed) // ߪೖঢ়ଶͷ֬ೝ XCTAssertFalse(PurchaseManager.shared.isAvailable(for: .premium)) } sessionͰfailઃఆΛ͢Δͱ ڧ੍తʹߪೖࣦഊͤ͞Δ͜ͱ͕Ͱ͖Δ
  26. આ໌͖͠Εͳ͔ͬͨ৽ػೳ Xcode؀ڥͷϨγʔτݕূ ࣌ؒܦաͷߴ଎Խ ฦۚॲཧͷςετ ϑΝϛϦʔڞ༗ ϓϩϞʔγϣϯΦϑΝʔ αʔόʔ௨஌ Ϣχοτςετͷͦͷଞͷ৽ػೳ ࣮ࡍͷৄࡉͳ࣮૷ Xcode

    12ͷϫʔΫΞϥ΢ϯυ Τϥʔέʔεͷݕূ ͓ࢼ͠ΦϑΝʔ
  27. ZennͷBooksͰৄ͍͠ղઆͱ࣮૷Λެ։͠·ͨ͠ ໢ཏతͳ৽ػೳΛ঺հͱ SwiftUI੡ͷׂͱ͔ͬ͠Γ࣮૷ͨ͠՝ۚαϯϓϧΞϓϦ͕ࡌͬͯ·͢ IUUQT[FOOEFWUBUUOCPPLTJPTJOBQQQVSDIBTF