paint-brush
Shyira mu bikorwa ibigeragezo byubusa muri porogaramu yawe hamwe nububikoKit 2: Intambwe ku yindina@namaswic
442 gusoma
442 gusoma

Shyira mu bikorwa ibigeragezo byubusa muri porogaramu yawe hamwe nububikoKit 2: Intambwe ku yindi

na Namaswi Chandarana11m2024/09/17
Read on Terminal Reader

Birebire cyane; Gusoma

Hamwe na StoreKit 2, Apple yazanye ibikoresho byongerewe imbaraga kugirango bigufashe kugenzura niba umukoresha yujuje ibisabwa kugirango atangire. Muri iyi ngingo, tuzakuyobora mugushira mubikorwa ibigeragezo kubuntu muri porogaramu yawe, byuzuye hamwe na kode ya kode kugirango tumenye neza abakoresha. Kandi witondere guhanga amaso "** Impanuro **" zinyanyagiye mu ngingo, aho mbagezaho ubushishozi bwihariye mubyambayeho.
featured image - Shyira mu bikorwa ibigeragezo byubusa muri porogaramu yawe hamwe nububikoKit 2: Intambwe ku yindi
Namaswi Chandarana HackerNoon profile picture
0-item
1-item


Gutanga ikigeragezo kubuntu ninzira nziza yo gushishikariza abakoresha kugerageza ibintu byingenzi bya porogaramu yawe, byongera amahirwe yo kubahindura mukwishyura abafatabuguzi. Hamwe na StoreKit 2, Apple yazanye ibikoresho byongerewe imbaraga kugirango bigufashe kugenzura niba umukoresha yujuje ibisabwa kugirango atangire. Muri iyi ngingo, tuzakuyobora mugushira mubikorwa ibigeragezo kubuntu muri porogaramu yawe, byuzuye hamwe na kode ya kode kugirango tumenye neza abakoresha. Tuzareba kandi ibizamini byo kugerageza kubakoresha kandi batujuje ibisabwa. Kandi witondere gukurikiranira hafi " Pro Tips " zinyanyagiye mu ngingo, aho nsangira ubushishozi bwihariye mubyambayeho!


Nigute Gushiraho Ibigeragezo Byubusa kuri Porogaramu Yawe Mububiko bwa App

Mbere yo gutangira code, menya neza ko ugena igenamiterere rya porogaramu yo kugura muri porogaramu y'Ububiko bwa App:

  1. Injira mububiko bwa porogaramu hanyuma ujye mu gice cya "Porogaramu zanjye".
  2. Hitamo porogaramu yawe hanyuma ujye kuri tab "Ibiranga" .
  3. Munsi ya "In-App Kugura," kora ibicuruzwa bishya byiyandikisha .
  4. Sobanura ibisobanuro byawe byo kwiyandikisha, harimo ibiciro nigihe cyo kugerageza kubuntu (urugero, iminsi 7) ushiraho itangiriro.
  5. Bika impinduka zawe.

Nigute ushobora gushiraho abiyandikisha ukareba niba uyikoresha yemerewe kugeragezwa kubuntu?

Nzakora ibi byoroshye nkwereka kode ya kode, kuburyo ushaka kubara ibyangombwa byikigereranyo kubakoresha

Kora SwiftUI kureba kugirango werekane itangwa ryubusa kandi ukoreshe imikoranire yabakoresha. Nzasiga ibitekerezo byinshi muri kode ya kode kugirango nkunyure.


 import StoreKit2 // StoreManager is responsible to communicate with Storekit Framework provided by Apple for monetization class StoreManager: ObservableObject { @Published var message: String = "" // We will use this property to display the right message to the user @Published var products: [Product] = [] // This will be responsible to store the products fetched that we defined // in App Store Connect // Fetch products from the App Store func fetchProducts() { Task { do { // product_id is the id that you would have defined in App Store Connect. let storeProducts = try await Product.products(for: ["product_id"]) products = storeProducts } catch { message = "Failed to fetch products: \(error.localizedDescription)" } } } // Initiate purchase func purchase() { guard let product = products.first else { // There is a possibility of products not being fetched from App Store Connect. // Pro Tip: From experience, even though we defined the products on App Store Connect, it is possible // that the products are not found post attempting to fetch. So, it is important to handle this case. message = "No product available." return } Task { do { let result = try await product.purchase() switch result { case .success(let verification): switch verification { case .verified: message = "Purchase successful!" case .unverified: message = "Could not verify the purchase." } case .userCancelled: message = "Purchase cancelled." case .pending: message = "Purchase is pending." @unknown default: message = "Unknown result." } } catch { message = "Purchase failed: \(error.localizedDescription)" } } } // Check if the user is eligible for a free trial func checkTrialEligibility() async -> Bool { guard let product = products.first else { return false } do { // So when you define a auto renewable subscriptions, there are usually bond in a group. The group can again be // found in App Store Connect let eligibility = try await product.subscription?.isEligibleForIntroOffer(for groupID: 111111) return eligibility ?? false } catch { message = "Error checking trial eligibility: \(error.localizedDescription)" return false } } }


 import SwiftUI import StoreKit struct SubscriptionView: View { @StateObject private var storeManager = StoreManager() @State private var isEligibleForFreeTrial = false var body: some View { VStack { Text("Unlock Premium Features") .font(.title) .padding() Text("Get a 7-day free trial of our premium subscription.") .multilineTextAlignment(.center) .padding() Button(action: { storeManager.purchase() }) { // Based on user status, we can display the text Text(isEligibleForFreeTrial ? "Start Free Trial" : "Start Subscription") .bold() .frame(width: 200, height: 50) .background(Color.blue) .foregroundColor(.white) .cornerRadius(10) } Text(storeManager.message) .padding() } .onAppear { storeManager.fetchProducts() checkTrialEligibility() } } private func checkTrialEligibility() { Task { isEligibleForFreeTrial = await storeManager.checkTrialEligibility() } } }

Ikizamini Cyubusa Ibihugu byujuje ibisabwa muri Xcode

Apple itanga ibikoresho bikomeye byo kugerageza ibihugu bitandukanye byabakoresha (urugero, bujuje ibisabwa cyangwa ntibemerewe kugeragezwa kubuntu) ukoresheje Ikizamini cya StoreKit muri Xcode :

  • Kora Ububiko bwa File File Iboneza:
    • Jya kuri File> Gishya> Idosiye ...> UbubikoKit Iboneza Idosiye muri Xcode.

    • Shiraho ibicuruzwa byawe byo kwiyandikisha, harimo ibihe byo kugerageza hamwe na leta zujuje ibisabwa.


  • Impanuro : Urashobora kandi gukora dosiye nshya yimiterere kugirango uhuze dosiye iboneza kuva muri App Store ihuza kandi ubwo buryo ntibukeneye gushiraho ibicuruzwa byose.


  • Wigane ibintu bitandukanye:

    • Muri Gahunda ya Muhinduzi munsi yamahitamo , hitamo ububiko bwibikoresho bya StoreKit.
    • Koresha porogaramu yawe mububiko bwibizamini bya StoreKit kugirango wigane ibintu bitandukanye:
      • Abemerewe kuburanishwa ku buntu:

        Kugereranya umukoresha wikigereranyo kubuntu, menya neza ko udafite ibikorwa mubikorwa byumuyobozi.

        Kubona umuyobozi wubucuruzi. Jya kuri DebugUbubikoKitGucunga ibikorwa


  • Ntibemerewe kuburanishwa kubuntu:

    Kugereranya umukoresha utemerewe kugeragezwa kubuntu. Urashobora kongeramo intoki abiyandikishije mubuyobozi bwubucuruzi. Urashobora gukanda kuri bouton yongeyeho kuri ecran ya transaction ya ecran hanyuma ugahitamo transaction ushaka kongeramo. Hano, ndagerageza gushiraho abiyandikisha buri kwezi kubakoresha. Nyuma yo kongeramo ibyo gucuruza no kongera gukoresha porogaramu, ugomba kubona ibyangombwa byo kugerageza byerekanwe nkibinyoma.


    Impanuro: Urashobora kandi gushiramo UUID hamwe no kugura, ukoresheje uyu murima kugirango ubike indangamuntu. Ubu buryo urashobora kwemeza umukoresha waguze kuri porogaramu yawe. Aya makuru arashobora gukurwa nyuma mumateka yubucuruzi.

Kora Ikizamini cya Sandbox

Ikizamini cya Sandbox kigufasha kugerageza kugura porogaramu yawe muri porogaramu no kwiyandikisha mu bidukikije bigana aho ibicuruzwa byinjira mu Ububiko bikaguha kandi umudendezo wo gushinyagurira imanza ebyiri nko guhagarika kugura, kugabana umuryango, no kwigana ibyaguzwe byakorewe hanze porogaramu cyangwa mu kindi gikoresho. Iragufasha kandi


Ariko mbere yikintu cyose, dore uburyo bwo gushiraho no gukoresha ibizamini bya sandbox:

  1. Kora Konti Yipimisha Sandbox:

    • Jya kuri Ububiko bwa Porogaramu Guhuza> Abakoresha no Kwinjira> Abagerageza Sandbox .
    • Kora konte nshya ya sandbox yipimisha utanga aderesi imeri idasanzwe, ijambo ryibanga, nibindi bisabwa.
  2. Injira hamwe na Konti Yipimisha Sandbox:

    • Ku gikoresho cyawe cyo kwipimisha, jya kuri Igenamiterere> Ububiko bwa porogaramu> Konti ya Sandbox .
    • Injira hamwe na sandbox yipimisha ibyangombwa wakoze.
  3. Koresha Porogaramu yawe muri Sandbox Mode:

    • Kubaka no gukoresha porogaramu yawe kubikoresho bifatika (kugerageza sandbox ntabwo ikora muri simulator).
    • Gerageza gutangira igeragezwa kubuntu cyangwa kugura ukoresheje konte ya sandbox yipimisha. Ibicuruzwa bizakomeza mubidukikije byumusenyi, bikwemerera kugerageza imigendekere yuzuye, harimo kwemererwa kugeragezwa kubuntu, kugura intsinzi, guhagarika, nibindi bihugu.
  4. Gerageza Ibihe Bitandukanye:

    • Umukoresha-Igihe cya mbere: Koresha konte ya sandbox kugirango ugure bwa mbere kugirango urebe ko igeragezwa ryubuntu ryatanzwe neza. Kugirango ukoreshe konte imwe ya sandbox kugirango ugerageze gukurikira QA, urashobora rwose gusubiramo ibyangombwa byumukoresha kandi ukanakuraho ibyakozwe byose kuri konte ya sandbox. Urashobora kubikora uhereye kububiko bwa App Store cyangwa Igenamiterere
    • Kugura byahagaritswe: Gerageza uburyo porogaramu ifata umukoresha uhagarika kugura mugihe cyo gutemba.
    • Kunanirwa kw'urusobe: Kwigana ibibazo byurusobe muguhagarika no guhuza umuyoboro kugirango urebe uko porogaramu ikemura ibicuruzwa byananiranye.
    • Ikigeragezo Cyubusa Ntibyemewe: Ibi ni amacenga make ariko ntibishoboka. Ubwa mbere, ushaka kuri Igenamiterere Store Ububiko bwa porogaramu → Kanda kuri konte ya sandbox → Kanda Ubuyobozi. Hano ugomba gushobora kongeramo ibikorwa byintoki kuri konte ya sandbox kubakoresha. Noneho, ugomba kuba ushobora kugerageza kutemerwa kubakoresha.



Impanuro: Konti ya Apple ntishobora kugira abiyandikisha benshi bakora, kubwibyo abakoresha babiri batandukanye ntibashobora kugura ibintu bitandukanye kuri porogaramu ukoresheje indangamuntu imwe ya Apple. Wemeze kugenzura porogaramu kuriyi dosiye.

Reba

https://developer.apple.com/documentation/storekit

https://iterambere

https://developer.apple.com/app-ububiko-huza/



L O A D I N G
. . . comments & more!

About Author

Namaswi Chandarana HackerNoon profile picture
Namaswi Chandarana@namaswic
I am a Senior Engineer focused on iOS app development and enhancing user experiences and well-being.

HANG TAGS

IYI ngingo YATANZWE MU...