Sie sind auf Seite 1von 16

StoreKit In-App Purchase Native Extension for iOS

Copyright 2011-2013 Milkman Games, LLC. All rights reserved.


http!!""".milkmangames.#om
$or s%pport, #onta#t s%pport&milkmangames.#om
Before you begin:
To View full AS3 documentation, see 'docs/as3docs/index.tml'.
Tis extension re!uires te A"# 3.$ S%& or iger, wic you can get at
http!!""".ado'e.#om!devnet!air!air-sdk-do"nload.html .
#e'iew 'exam(le/Store&it)xam(le.as' for a sam(le a((lication.
*ote tat Store&it)xam(le.as is a %ocument +lass. "f you're a ,las -rofessional user and don't
.now ow to use a document class, see te a((endix /0sing te )xam(le +lass in ,las +S1/ at te
end of tis guide.
1. Set Up In-App Purchase in iTunes Connect
(he )tore*it e+tension makes adding in-app p%r#hases to yo%r i,) Appli#ation easy- ho"ever, setting %p the
program on Apple.s developer "e'site takes a /e" steps
Create a New App ID
1. Go to http!!developer.apple.#om , and sele#t the i,) 0eveloper area.
2. $rom the men% on the right, sele#t .Certi/i#ates, 1denti/iers, 2 3ro/iles..
3. 4o% need to #reate a #%stom App 10 /or yo%r p%r#hase-ena'led appli#ation. Choose .1denti/iers. /rom
the men%, then the 3l%s 567 to Add a ne" App 10.
8. $or .0es#ription., enter a des#ription /or yo%r app. (his "ill 'e %sed to easily identi/y the App "ithin the
3rovisioning 3ortal, '%t "on9t 'e sho"n to %sers. $or .App 10 3re/i+., sele#t .:se (eam 10.. $or ;+pli#it
App 10, enter the 10 /or yo%r app, s%#h as .#om.yo%r#ompany.game.. (ake note o/ this 10 as yo% "ill
have to %se later in yo%r A1< Appli#ation 0es#riptor /ile.
Create a New Provisioning Profile for Your Application
=. >o", ret%rn to Certi/i#ates, 1denti/iers, 2 3ro/iles "indo", and sele#t 3rovisioning 3ro/iles /rom the le/t
hand side.
?. Choose the 3l%s 567 '%tton in the top right. Choose .i,) App 0evelopment. to #reate yo%r
development pro/ile and press Contin%e.
@. ,n the ne+t s#reen, sele#t the App 10 yo% #reated /or yo%r app earlier.
A. Complete the on s#reen prompts to generate and do"nload the .mo'ileprovision. 4o% "ill %se this
.mo'ileprovision /or signing yo%r apps "ith A1<.
B. You may repeat these steps to create a Distribution Profile when you're ready to submit your
app to the App Store.
10. <et%rn to the main developer page, and #hoose iTunes Connect. At this time, i/ yo% haven.t already
a##epted the 3aid Appli#ation #ontra#t %nder .Contra#ts, (a+, and Canking., do so no".
A In-App Purchases to Your Application
11. >o" yo% need to register yo%r Appli#ation "ith Apple. $rom i(%nes Conne#t, sele#t .Manage 4o%r
Appli#ations., and add a >e" Appli#ation.
12. ,n the .App 1n/ormation. s#reen, enter the App Name /or yo%r app. Choose a SK Number o/ yo%r
#hoi#e. ,or Bundle "%, you must now select te Bundle "% you created in Ste( 2. Choose
.Contin%e.. $inish setting %p the rest o/ the 'asi# in/ormation /or yo%r ne" App. 1/ yo% need
pla#eholder graphi#s /or s#reenshots and i#ons, some are provided in the !t%torial /older.
13. Dhen yo%.re done, sele#t yo%r ne" Appli#ation, and #hoose .Manage 1n-App 3%r#hases..
18. ,n the ne+t s#reen, #hoose .Create >e". to add an 1n-App 3%r#hase prod%#t.
1=. 4o% no" #an #hoose 'et"een Consumable! Non"Consumable and Auto"#enewable Subscriptions
prod%#t types. $ollo" the des#riptions on this page /or more in/ormation. ;ssentially, consumable
items #an 'e .%sed %p.- things like magi# spells- and non"consumable items are permanent /eat%res E
s%#h as a level pa#k.
1?. ;nter the in/ormation /or yo%r 3rod%#t on the ne+t s#reen. $or Product $D! %se Apple.s
re##ommended s#heme o/ C%ndle10.prod%#t10- /or instan#e, i/ yo% named yo%r '%ndle
.#om.yo%r#ompanysite.yo%rappname. in )tep 8, yo% might give an 10 o/
.#om.yo%r#ompanyname.yo%rappname.Level3a#k. to yo%r Level 3a#k prod%#t.
1@. 4o% m%st #hoose .Add Lang%age. and add at least one lang%age de/inition. $ill in the Display Name
5"hat %sers "ill see7 and description and #hoose .)ave..
1A. $or .3ri#ing and Availa'ility., set Cleared for Sale to Yes. $or .3ri#e (ier., #hoose the #ost o/ the item.
$or the )#reenshot, %pload an image o/ yo%r prod%#t in a#tion. (his is not sho"n to %sers, '%t is meant
/or Apple.s revie" team to get an idea o/ "hat the prod%#t is s%pposed to do. 4o% #an %pload a
pla#eholder image /or no" /rom the !t%torial /older i/ yo% "ish.
1B. <epeat the pro#ess /or ea#h 3rod%#t yo% "ant to add. Dhen yo%.re /inished, sele#t .0one.. Ce s%re
yo%.ve noted the e+a#t 1ds o/ all yo%r prod%#ts 'e#a%se yo% "ill need them in yo%r appli#ation.
Create a Test User in the Apple San!o"
20. Almost doneF (he /inal step is to add a (est :ser to the )and'o+. A (est :ser is a ./ake. i(%nes
a##o%nt, that yo% #an %se /or testing in-app p%r#hases. 1t "ill 'ehave G%st like a real a##o%nt, e+#ept no
money is a#t%ally 'e ded%#ted "hen the test p%r#hases happen. <et%rn to the i(%nes Conne#t s#reen,
and #hoose .Manage :sers..
21. Choose .Add >e" :ser. /rom the .Manage (est :sers. s#reen.
22. (his is a /ake %ser /or testing p%rposes. Later, yo% "ill 'e a'le to login to the store "hen testing yo%r
appli#ation, and #omplete the p%r#hase /lo" "itho%t a#t%ally having any money #harged to yo%r
a##o%nt. $or %irst Name and &ast Name, enter "hatever yo% "ish. $or email address, yo% do not
need to enter a real address- '%t it does need to 'e %niH%e. 4o% sho%ld #hoose an email address at
yo%r o"n domain and remem'er it 5even i/ the address doesn.t a#t%ally e+ist7, /or instan#e
.tester1&yo%r#ompany.#om.. Make s%re yo% mark do"n the pass"ord yo% #hoose as "ell. $ill in the
rest o/ the relevant in/ormation and press .)ave..
#. Install the AI$ %.& SD' in (our ID)
The StoreKit e'tension re(uires the A$# ).* SDK or hi+her. 4o% #an do"nload the latest A1< )0* /rom
http!!""".ado'e.#om!devnet!air!air-sdk-do"nload.html. 1/ yo% haven.t already installed the A1< 3.= )0*
5or higher7 /or yo%r $lash C)? or $lash C%ilder 10;, /ollo" the instr%#tions 'elo"
,nablin+ the A$# ).* SDK -or hi+her. in %lash Professional CS/01
1. :nIip the A1< 3.= )0* 5or higher7 pa#kage to a lo#ation on yo%r hard drive.
2. La%n#h $lash 3ro/essional C)?.
3. )ele#t Jelp K Manage A1< )0*...
8. 3ress the 3l%s 567 C%tton and navigate to the lo#ation o/ the %nIipped A1< )0*
=. 3ress ,*
?. )ele#t $ile K 3%'lish )ettings
@. )ele#t the A1< 3.= 5or higher7 )0* /or i,) /rom the .(arget. 0ropdo"n men%
,nablin+ the A$# ).* SDK -or hi+her. in %lash 2uilder 3./0 on 4indows1
1. :nIip the A1< 3.= )0* pa#kage to a lo#ation on yo%r hard drive.
2. Close $lash C%ilder.
3. Lo#ate the $lash C%ilder )0* dire#tory. ,n the 3C, this is %s%ally #L3rogram $ilesLAdo'eLAdo'e $lash
C%ilder 8.?Lsdks .
8. Make a #opy o/ the #%rrent $le+ )0* dire#tory, and give it a des#riptive name. $or instan#e, #opy the
M8.?.0M )0* /older inside !sdks and name the #opy M8.?.0NA1<3=M.
=. Copy and paste the #ontents o/ the A1< 3.= )0* on top o/ the 8.?.0NA1<3= dire#tory. A##ept all
#hanges.
?. ;dit the /le+-sdk-des#ription.+ml /ile inside the ne" dire#tory, and #hange the val%e o/ the OnameK tag
to .$le+ 8.?.0 5A1< 3.=7..
@. ,pen $lash C%ilder and #hoose 3roGe#t K 3roperties K $le+ Compiler K Con/ig%re $le+ )0*s.
A. 3ress .Add. and navigate to the ne" /older lo#ation.
,nablin+ the A$# ).* SDK -or hi+her. in %lash 2uilder 3./0 on a 5ac1
1. Copy the #ontents A1< 3.= )0* pa#kage to a lo#ation on yo%r hard drive.
2. Close $lash C%ilder.
3. Lo#ate the $lash C%ilder )0* dire#tory. ,n the Ma#, it is %s%ally !Appli#ations!Ado'e $lash C%ilder
8.?!sdks!. ,n the 3C, #L3rogram $ilesLAdo'eLAdo'e $lash C%ilder 8.?Lsdks .
8. Create a ne" /older inside the )0* /older, #alled A1<3=)0* and #opy the #ontents o/ the )0* pa#kage
into it.
=. ,pen the (erminal, and merge the A1< 3.= )0* /iles into yo%r #%rrent )0* dire#tory
sudo cp -Rp /Applications/Adobe\ Flash\ Builder\ 4.6/sdks/AIR35S!/ /Applications/Adobe\ Flash\
Builder\ 4.6/sdks/4.6."/
?. ;dit the /le+-sdk-des#ription.+ml /ile inside the ne" dire#tory, and #hange the val%e o/ the OnameK tag
to .$le+ 8.?.0 5A1< 3.=7..
@. ,pen $lash C%ilder and #hoose 3roGe#t K 3roperties K $le+ Compiler K Con/ig%re $le+ )0*s.
A. 3ress .Add. and navigate to the ne" /older lo#ation.
%. Inclue the Store'it )"tension *i!rar(
Add the #om.milkmangames.e+tensions.)tore*it.ane to yo%r proGe#t. (hese are in the !e+tension /older o/ the
e+tension pa#kage Iip /ile.
$n %lash Professional CS/01
1. Create a ne" proGe#t o/ the type .A1< /or i,).
2. )ele#t $ile K 3%'lish )ettings...
3. )ele#t the "ren#h i#on ne+t to .)#ript. /or .A#tions#ript )ettings.
8. )ele#t the Li'rary 3ath ta'
=. 3ress the .Cro"se /or >ative ;+tension 5A>;7 $ile. '%tton and sele#t the
#om.milkmangames.e+tensions.)tore*it.ane /ile. 3ress ,*.
?. Make s%re yo%.re %sing the A1< 3.= 5or higher7 )0* per the instr%#tions in )e#tion 2.
@. )ele#t $ileK3%'lish )ettings...
A. $or .(arget. )ele#t .A1< 3.= /or i,). 5or higher version7
$n %lash 2uilder 3./01
1. Go to Project Properties
2. )ele#t Native Extensions
3. Choose Add ANE... and navigate to the #om.milkmangames.e+tensions.)tore*it.ane /ile
8. Make s%re the .pa#kage. 'o+ is #he#ked /or yo%r target, %nder A#tions#ript C%ild 3a#kaging
5a6e sure you're usin+ the A$# ).* or hi+her SDK per the instructions in Section 7.
+. API ,uic- Start
(he )tore*it e+tension #an 'e %p and r%nning in a /e" simple #alls. )ee .e'ample8StoreKit,'ample.as. /or
a /%ll e+ample, in#l%ding making p%r#hases, restoring transa#tions, saving state, and more.
Initiali.e the )"tension
1. 1mport the A31 Classes
i#port co#.#ilk#an$a#es.nati%ee&tensions.ios.'(
i#port co#.#ilk#an$a#es.nati%ee&tensions.ios.e%ents.'(
2. $irst, initialiIe the A31 and #reate an instan#e o/ the )tore*it o'Ge#t. Make s%re the #%rrent plat/orm
"ill s%pport i,) 3%r#hases 5as in, it.s not a 3C or Android, et#.7
i)*Store!it.isSupported*++
,
Store!it.create*+(
-
else ,
trace*.Store!it onl/ 0orks on i1S2.+(
return(
-
3. Che#k i/ the spe#i/i# 0evi#e "ill s%pport 1n-App 3%r#hases. 1t is possi'le /or parental #ontrols or other
settings to prevent p%r#hases /rom 'eing made at all, so yo% need to #he#k this #ase /irst 'e/ore %sing
the other methods.
i)*2Store!it.store!it.isStore!itA%ailable*++
,
trace*.this de%ice has purchases disabled..+(
return(
-
*oa Details a!out In-App Proucts
8. :sing the )tore*it.store*it.load3rod%#t0etails method, yo% #an retrieve in/ormation a'o%t availa'le
p%r#hases, s%#h as title, des#ription, pri#e, and so on. (o %se these method, pass in a Pe#tor array o/
prod%#t 10s yo% #reated in Q)e#tion 1 Add 1n-App 3%r#hases to 4o%r Appli#ationR
// the )irst thin$ to do is to suppl/ a list o) product ids /ou 0ant to displa/3
// and Apple4s ser%er 0ill respond 0ith a list o) their details *titles3 price3 etc+
// assu#in$ the ids /ou pass in are %alid. 5%en i) /ou don4t need to use this
// in)or#ation3 /ou #ust #ake the details re6uest be)ore doin$ a purchase.
// the list o) ids is passed in as an as3 %ector *t/ped Arra/.+
%ar productId7ist89ector.:Strin$;<ne0 9ector.:Strin$;*+(
productId7ist.push*.co#./ourco#pan/./ourapp.7e%el=ack.+(
productId7ist.push*.co#./ourco#pan/./ourapp.>a$icSpell.+(
// 0hen this is done3 0e4ll $et a =R1?@AB5AAI7SB71A5 or =R1?@AB5AAI7SBFAI75
e%ent and $o on )ro# there...
Store!it.store!it.load=roductetails*productId7ist+(
=. 1n response to this reH%est, a Store!it5%ent.=R1?@AB5AAI7SB71A5 event "ill 'e dispat#hed. 1ts
.%alid=roducts property "ill #ontain an array o/ Store!it=roduct o'Ge#ts, "ith additional in/ormation
a'o%t the prod%#ts. 1/ any o/ the 10s yo% reH%ested are not valid, they "ill 'e listed in the array
property .in%alid=roductIds
// listen )or a response )ro# load=roductetails*+8
Store!it.store!it.add5%ent7istener*Store!it5%ent.=R1?@AB5AAI7SB71A53on=roducts+(
)unction on=roducts*e8Store!it5%ent+8%oid
,
)or each*%ar product8Store!it=roduct in e.%alid=roducts+
,
trace*.I8 .Cproduct.productId+(
trace*.Aitle8 .Cproduct.title+(
trace*.escription8 .Cproduct.description+(
trace*.Strin$ =rice8 .Cproduct.localiDed=rice+(
trace*.=rice8 .Cproduct.price+(
-
trace*.7oaded .Ce.%alid=roducts.len$thC. =roducts..+(
i) *e.in%alid=roductIds.len$th;"+
,
trace*.E5RRF8 in%alid product ids8.Ce.in%alid=roductIds.Goin*.3.++(
-
-
?. 4o% m%st also add an event listener /or Store!it5rror5%ent.=R1?@AB5AAI7SBFAI75, "hi#h "ill 'e
dispat#hed i/ an error o##%rs "ith the prod%#t reH%est. 4o% sho%ld 'e s%re to in#l%de this listener to
avoid errors halting yo%r program
// listen )or 5RR1R response )ro# load=roductetails*+8
Store!it.store!it.add5%ent7istener*Store!it5rror5%ent.=R1?@AB5AAI7SBFAI753
on=roductsFailed+(
)unction on=roductsFailed*e8Store!it5rror5%ent+8%oid
,
trace*.error loadin$ products8 .Ce.te&t+(
-
Purchase an In-App Prouct
@. Dhen yo%r %ser "ants to p%r#hase a prod%#t, yo% #an %se the
Store!it.store!it.purchase=roduct*+ /%n#tion. 3ass the prod%#t 10 yo% #reated in i(%nes Conne#t
as the /irst parameter, and 5optionally7, the H%antity o/ items to '%y as the se#ond parameter
// this call purchases a product. Ahe second para#eter is an
// optional 6uantit/- i) /ou 0ant to purchase #ore than one ite# at a ti#e.
Store!it.store!it.purchase=roduct*.co#./ourco#pan/./ourapp.>a$icSpell.3H+(
A. 1/ the p%r#hase s%##eeds, a Store!it5%ent.=?R@IAS5BS?@@555 event "ill 'e dispat#hed. At this
time, yo% sho%ld r%n #ode to QgiveR the p%r#hased item to the %ser "ithin yo%r appli#ation
// this e%ent is )ired 0hen a purchase $oes throu$h ok
Store!it.store!it.add5%ent7istener*Store!it5%ent.=?R@IAS5BS?@@5553on=urchaseSuccess+(
)unction on=urchaseSuccess*e8Store!it5%ent+8%oid
,
// /our app is no0 responsible )or 4$i%in$4 the user 0hate%er the/ bou$ht2
$i%e?serIte#*e.productId+(
-
B. 1/ the %ser #an#els the p%r#hase, Store!it5%ent.=?R@IAS5B@AJ@5775 "ill 'e dispat#hed instead
// this e%ent is )ired 0hen a purchase $ets cancelled
Store!it.store!it.add5%ent7istener*Store!it5%ent.=?R@IAS5B@AJ@57753on=urchase@ancel+(
)unction on=urchase@ancel*e8Store!it5%ent+8%oid
,
trace*.the user decided not to bu/8 .Ce.productId+(
-
10. 4o% m%st also add an event listener /or Store!it5rror5%ent.=?R@IAS5BFAI75, "hi#h "ill 'e
dispat#hed i/ an error o##%rs "ith the p%r#hase reH%est. 4o% sho%ld 'e s%re to in#l%de this listener to
avoid errors halting yo%r program
// listen )or 5RR1R response )ro# purchase=roduct*+8
Store!it.store!it.add5%ent7istener*Store!it5rror5%ent.=?R@IAS5BFAI753
on=urchaseFailed+(
)unction on=urchaseFailed*e8Store!it5rror5%ent+8%oid
,
trace*.error purchasin$ product8 .Ce.te&t+(
-
$estore Previous Transactions
11. Apple reH%ires that yo%r app in#l%des a '%tton to Q<estore (ransa#tions.R 1/ the %ser %ninstalls yo%r
app, or gets a ne" devi#e, they "ill %se this '%tton to restore any non-#ons%ma'le items they had
previo%sly p%r#hased. (o initiate a transa#tion restore, #all
Store!it.store!it.restoreAransactions*+
// this 0ill #ake a =?R@IAS5BS?@@555 e%ent happen a$ain )or
// an/thin$ non-consu#able the user has bou$ht pre%iousl/ )or /our app.
// Khen it4s all done3 the ARAJSA@AI1JSBR5SA1R5 e%ent 0ill occur.
Store!it.store!it.restoreAransactions*+(
12. A/ter #alling restoreAransactions*+, a StoreKitEvent.PURCHASE_SUCCEEDED e9ent for all pre9ious
transactions is :replayed;. 1/ yo%.ve implemented the Store!it5%ent.=?R@IAS5BS?@@555
#orre#tly in step A, no additional a#tion sho%ld 'e reH%ired to handle the restore.
Dhen there are no more previo%s p%r#hase events to 'e replayed, the
Store!it5%ent.ARAJSA@AI1JSBR5SA1R5 event "ill 'e dispat#hed
// this e%ent is )ired 0hen all the old =?R@IAS5BS?@@555 e%ents 0ere repla/ed
Store!it.store!it.add5%ent7istener*Store!it5%ent.ARAJSA@AI1JSBR5SA1R53
onAransactionsRestore@o#plete+(
)unction onAransactionsRestore@o#plete*e8Store!it5%ent+8%oid
,
// /our app $ot =?R@IAS5BS?@@555 )or each old purchase3 and should4%e
// $i%e the ite#s to the user.
trace*.restore co#plete2.+(
-
13. 4o% m%st also add an event listener /or Store!it5rror5%ent.ARAJSA@AI1JBR5SA1R5BFAI75, "hi#h
"ill 'e dispat#hed i/ an error o##%rs "ith the restore reH%est. 4o% sho%ld 'e s%re to in#l%de this listener
to avoid errors halting yo%r program
// listen )or 5RR1R response )ro# purchase=roduct*+8
Store!it.store!it.add5%ent7istener*Store!it5rror5%ent.ARAJSA@AI1JBR5SA1R5BFAI753
onRestoreFailed+(
)unction onRestoreFailed*e8Store!it5rror5%ent+8%oid
,
trace*.so#ethin$ 0ent 0ron$ restorin$ transactions8 .Ce.te&t+(
-
/0ptional1 Displa(ing In-App Prouct 2iews
18. ,ptionally, the e+tension #an display a "indo" inside yo%r app /or any prod%#t on the i(%nes )tore-
5apps, songs, movies, et#.7. (his #an 'e %se/%l /or promoting yo%r other apps, or other related
prod%#ts, /rom "ithin yo%r o"n app.
1=. 0isplaying a prod%#t vie" reH%ires the i(%nes 3rod%#t 10, "hi#h #an 'e o'tained 'y sear#hing /or the
prod%#t in i(%nes, right-#li#king on its image, and #opying the image :<L. (hen #opy the n%meri# 10
val%e /rom the :<L 5/or instan#e the .383200?=?. /rom .https!!it%nes.apple.#om!%s!app!angry-
'irds!id383200?=?. is the i(%nes 10 /or Angry Cirds7.
1?. 0isplaying a prod%#t vie" reH%ires i,) ? or higher. 0etermine "hether the /%n#tionality is availa'le 'y
#he#king Store!it.store!it.is=roduct9ie0A%ailable*+, and i/ so, #alling displa/=roduct9ie0*+
"ith the i(%nes 10
i)*Store!it.store!it.is=roduct9ie0A%ailable*++
,
Store!it.store!it.displa/=roduct9ie0*.343L""656.+(
-
1@. A prod%#t vie" "indo" "ill 'e displayed and start loading the prod%#t in/ormation. Dhen this vie"
appears, Store!it5%ent.=R1?@AB9I5KBIS=7AM5 is dispat#hed
// listen )or 0hen the product %ie0 is sho0n
Store!it.store!it.add5%ent7istener*Store!it5%ent.=R1?@AB9I5KBIS=7AM53
on=roductispla/ed+(
)unction on=roductispla/ed*e8Store!it5%ent+8%oid
,
trace*.sho0ed product %ie0 )or itunes id8 .Ce.productId+(
-
1A. Dhen this in/ormation has /inished loading and is sho"n to the %ser,
Store!it5%ent.=R1?@AB9I5KB71A5 is dispat#hed
// listen )or 0hen the product %ie04s inner content is loaded
Store!it.store!it.add5%ent7istener*Store!it5%ent.=R1?@AB9I5KB71A53
on=roduct9ie07oaded+(
)unction on=roduct9ie07oaded*e8Store!it5%ent+8%oid
,
trace*.content loaded in %ie0 )or itunes id8 .Ce.productId+(
-
1B. 4o% m%st also add an event listener /or Store!it5rror5%ent.=R1?@AB9I5KBFAI75, "hi#h "ill 'e
dispat#hed i/ an error o##%rs loading the i(%nes #ontent. 4o% sho%ld 'e s%re to in#l%de this listener to
avoid errors halting yo%r program
// listen )or 5RR1R response loadin$ the product %ie0
Store!it.store!it.add5%ent7istener*Store!it5rror5%ent.=R1?@AB9I5KBFAI753
on=roduct9ie0Failed+(
)unction on=roduct9ie0Failed*e8Store!it5rror5%ent+8%oid
,
trace*.so#ethin$ 0ent 0ron$ 0ith the product %ie08 .Ce.te&t+(
-
20. Dhen the %ser #loses the prod%#t vie" "indo", Store!it5%ent.=R1?@AB9I5KBIS>ISS5 is
dispat#hed
// listen )or 0hen the product %ie0 is dis#issed
Store!it.store!it.add5%ent7istener*Store!it5%ent.=R1?@AB9I5KBIS>ISS53
on=roductispla/ed+(
)unction on=roductis#issed*e8Store!it5%ent+8%oid
,
trace*.the user closed the product %ie0 )or .Ce.productId+(
-
/0ptional1 3anling Apple-3oste Downloaa!le Content
This is an an ad9anced user feature. Before implementing downloads of Apple-osted content, note that
i,) ? or higher is reH%ired. 1/ yo% s%pport i,) 8 or =, yo%.ll need an alternate strategy /or hosting.
4o% m%st #reate and %pload the do"nloada'le #ontent %sing S#ode 86, "ith the Q1n-App 3%r#hase
ContentR prod%#t template. (he C%ndle 1denti/ier needs to mat#h that o/ the #orresponding 1n-App
3rod%#t in i(%nes Conne#t. :pload it 'y #hoosing 3rod%#tKAr#hive /rom the SCode men%.
4o% sho%ld 'e /amiliar "ith the /lash./ilesystem.$ile A31 and the )e#%rity0omain restri#tions that apply
to i,) /ile management in Ado'e A1<.
21. ,ptionally, Apple "ill host do"nloada'le /iles /or non-#ons%ma'le items /or yo%, i/ yo%r app r%ns on i,)
? or higher. 4o% #an determine i/ the appli#ation is #apa'le o/ do"nloading Apple-Josted #ontent at
r%ntime 'y %sing the Store!it.store!it.isIosted@ontentA%ailable*+ method. 1/ it ret%rns /alse,
the devi#e is r%nning an older version o/ i,) and no do"nloading "ill o##%r.
1/ it ret%rns tr%e, yo% #an add listeners /or the three do"nload events dispat#hed 'y the e+tension
i)*2Store!it.store!it.isIosted@ontentA%ailable*++
,
trace*.this de%ice is not capable o) do0nloadin$ apple-hosted content..+(
-
else
,
Store!it.store!it.add5%ent7istener*Store!it5%ent.1KJ71AB?=AA53
ono0nload?pdated+(
Store!it.store!it.add5%ent7istener*Store!it5%ent.1KJ71ABFIJISI53
ono0nloadFinished+(
Store!it.store!it.add5%ent7istener*Store!it5rror5%ent.1KJ71ABFAI753
ono0nloadFailed+(
-
22. A/ter a s%##ess/%l p%r#hase o/ a non-#ons%ma'le item that in#l%des Apple-hosted do"nloada'le
#ontent, the e+tension "ill a%tomati#ally 'egin the do"nload o/ the pa#kage /rom Apple.s server. As
the do"nload progresses, Store!it5%ent.1KJ71AB?=AA5 events "ill 'e periodi#ally dispat#hed,
indi#ating the progress o/ the do"nload
)unction ono0nload?pdated*e8Store!it5%ent+8%oid
,
trace*.do0nloadin$ ite#8 .Ce.productId+(
// e.do0nload=ro$ress is a "-H." scale
trace*.percent co#plete8.C*e.do0nload=ro$ress'H""++(
trace*.seconds re#ainin$8.Ce.do0nloadAi#eRe#ainin$+(
trace*.content %ersion8.Ce.do0nload9ersion+(
-
23. Dhen the do"nload is #ompleted, Store!it5%ent.1KJ71ABFIJISI5 is dispat#hed. (he e+tension
"ill a%tomati#ally %npa#k the do"nloaded #ontent into a s%'dire#tory o/ yo%r appli#ation.s lo#al storage
path, and provide the lo#ation o/ the do"nloaded #ontent in the do0nload=ath property o/ the event.
4o% may then %se the )lash.)iles/ste#.File o'Ge#t to a##ess the /iles and pro#ess them in yo%r app,
or move them to a ne" lo#ation. 1n the e+ample 'elo", "e look thro%gh the do"nload dire#tory and
load any 3>G /iles /o%nd on to the stage
i#port )lash.displa/.7oader(
i#port )lash.)iles/ste#.File(
i#port )lash.s/ste#.Applicationo#ain(
i#port )lash.s/ste#.7oader@onte&t(
i#port )lash.s/ste#.Securit/o#ain(
// dispatched 0hen a do0nload has )inished
)unction ono0nload?pdated*e8Store!it5%ent+8%oid
,
trace*.)inished do0nloadin$8.Ce.productId+(
%ar do0nloadirector/8File<ne0 File*e.do0nload=ath+(
i) *do0nloadirector/.e&ists+
,
%ar contents8Arra/<theStu)).$etirector/7istin$*+(
)or each*%ar )ile8File in contents+
,
i) *)ile.e&tension<<.pn$.+
,
%ar conte&t87oader@onte&t<ne0 7oader@onte&t*true3
Applicationo#ain.currento#ain+(
%ar loader87oader<ne0 7oader*+(
loader.load*ne0 ?R7Re6uest*)ile.url+3conte&t+(
sta$e.add@hild*loader+(
-
-
-
-
28. 4o% m%st also add an event listener /or Store!it5rror5%ent.1KJ71ABFAI75, "hi#h "ill 'e
dispat#hed i/ an error o##%rs "ith the do"nload. 4o% sho%ld 'e s%re to in#l%de this listener to avoid
errors halting yo%r program
// listen )or 5RR1R response durin$ a do0nload
Store!it.store!it.add5%ent7istener*Store!it5rror5%ent.1KJ71ABFAI753
ono0nloadFailed+(
)unction ono0nloadFailed*e8Store!it5rror5%ent+8%oid
,
trace*.so#ethin$ 0ent 0ron$ 0ith the do0nload8 .Ce.te&t+(
-
&. Upate Your Application Descriptor
4o%.ll need to 'e %sing the A1< 3.= or higher )0*, in#l%de the e+tension in yo%r Appli#ation 0es#riptor SML.
$or an e+ample, see 'e'ample8app.'ml'. 5<emem'er, the OidK se#tion m%st e+a#tly mat#h yo%r i(%nes
Conne#t id, so yo% #an.t #opy that part o/ the e+ample +ml ver'atim.7
1. )et yo%r A1< )0* to 3.= 5or higher7 in the app des#riptor /ile
:application &#lns<.http8//ns.adobe.co#/air/application/3.5.;
2. 1n#l%de a link to the e+tension in the des#riptor
:e&tensions;
:e&tensionI;co#.#ilk#an$a#es.e&tensions.Store!it:/e&tensionI;
:/e&tensions;
3. Make s%re that yo%r OidK property exactly mat#hes the App 10 yo% #reated in i(%nes Conne#t.
4. 5uiling for Test 2s 5uiling for $elease
1. 4hen testin+1 Ce s%re the .mo'ileprovision /ile yo% '%ilt the ipa "ith "as yo%r de9elopment
pro9ision created in Section <! under :+reate a *ew -ro'isioning -rofile for 3our
A((lication4. 5'%t yo% #an and sho%ld %se the distri'%tion mo'ileprovision "hen '%ilding yo%r /inal
app to %pload to the App )tore.7 You'll also need to ma6e sure the pro9ision is installed on the
Test phone = you can >ust dra+ the file to iTunes to do this.
2. 4hen releasin+ to the store1 Ce s%re the .mo'ileprovision /ile yo% '%ilt the ipa "ith "as yo%r
release pro9ision created in Seciton <! under :+reate a *ew -ro'isioning -rofile for 3our
A((lication4.
6. Testing Purchases with (our Test User Account
1n )e#tion 1, yo% #reated a (est :ser in i(%nes Conne#t /or testing the p%r#hase /lo" "itho%t a#t%ally spending
money. 4o% sho%ld %se this a##o%nt "hen testing yo%r implementation. $ollo" these steps e+a#tly to r%n "ith
the (est :ser
1. Make s%re yo%r appli#ation des#riptor +ml is %sing yo%r e+a#t app id #reated in )e#tion 1
2. Make s%re "hen '%ilding yo%r appli#ation yo% are %sing the ipa-de'%g or ipa-de'%g-interpreter target
3. Make s%re "hen '%ilding yo%r appli#ation yo% are %sing the development mo'ileprovision /ile yo%
#reated in )e#tion 1
8. Ce/ore starting yo%r app on the devi#e, go to Settin+s?Store 5or )ettings K i(%nes 2 App )tore7,
sele#t yo%r %ser, and Si+n @ut.
=. )tart yo%r test app. Dhen yo% try to make a p%r#hase, it "ill prompt yo% to sign in,%se the test %ser
email and pass"ord yo% #reated in i(%nes Conne#t, in )e#tion 1, Q!reate a "est #ser in te Apple
$andbox%.
7. Trou!leshooting Co88on Pro!le8s
:Aow do $ use the StoreKit,'ample.as file in %lash Professional CS/B;
$irst, #reate the appli#ation, add the e+tension, and per/orm i(%nes Conne#t )et%p, 'y /ollo"ing this g%ide,
)e#tions 1-3.
Copy and paste )tore*it;+ample.as into the same /older as yo%r ./la. 0o not #opy and paste its #ontents
on to the timeline. (hat "ill not "ork.
Change the val%es QmyNnon#ons%ma'leR and QmyN#ons%ma'leR at the top o/ )tore*it;+ample.as to mat#h
the 3rod%#t 10s yo% #reated in i(%nes Conne#t.
1n $lash properties, %nder .0o#%ment Class., type .)tore*it;+ample. 5no H%otes7 and press ,*.
C%ild and install the appli#ation. Ce s%re to %se yo%r test %ser a##o%nt as des#ri'ed in )e#tion @, Q(esting
3%r#hases "ith yo%r (est :ser A##o%ntR.
:4hy doesn't the e'tension wor6 when $ run my swf on my 5ac 8 Android 8 4indows ComputerB;
"e extension uses features tat are built into te i&$ operating system. "e extension will only wor'
wen you run it on an i&$ pone or tablet.
:4hy won't my app Connect to the iTunes StoreB;
Peri/y that the .'%ndle id. in i(%nes Conne#t ;SAC(L4 mat#hes the appli#ation id in yo%r A1< mani/est
.+ml /ile.
$lash C%ilder "ill sometimes rename yo%r App 10 in the appli#ation SML /rom .#om.yo%r#ompany.app.
to .#om.yo%r#ompany.app-de'%g. "hen #ompiling to a de'%g target. C%ild "ith a release target or
man%ally /i+ the .+ml /ile i/ this is the #ase.
Make s%re yo%.ve agreed to the 3aid Appli#ations #ontra#t "ith Apple in the Contra#ts se#tion o/ i(%nes
Conne#t.
Make s%re that yo%r app id in yo%r appli#ation.+ml e+a#tly mat#hes the App 10 yo% #reated provision
/iles /or in )tep 1
Make s%re yo% are %sing the #%stom provision /iles #reated in )e#tion 1 /or yo%r App 10
Make s%re the prod%#t 1ds yo% pass to load3rod%#t0etails57 mat#h e+a#tly the ones yo% #reated in
i(%nes Conne#t
Ce s%re yo% are %sing a test %ser a##o%nt as des#ri'ed in )e#tion @, Q(esting 3%r#hases "ith yo%r (est
:ser A##o%ntR.
4o% may need to "ait 28 ho%rs a/ter #reating prod%#ts in i(%nes Conne#t 'e/ore they are availa'le on
the Apple test servers.
$n"App Purchase will not wor6 on Cailbro6en de9icesD
:$'m 'stuc6' in sandbo' mode and want to +o bac6 to my re+ular iTunes Store accountD;
Log o%t o/ the App )tore, #lose and %ninstall yo%r A1< app, and /or#e #lose the App )tore appli#ation.
<estart the App )tore and log in "ith yo%r a#t%al personal a##o%nt.
;very time yo%r test app "ith a mo'ileprovision /or development is r%n, yo% "ill re-enter sand'o+
mode. 4o% may have to repeat the pro#ess a'ove to e+it.
:4hy does my app stop respondin+ after $ ma6e a re(uestB;
<%n in de'%g mode to see i/ there are any errors. Make s%re yo% are #apt%ring all the
)tore*it;rror;vent.s /or the #alls yo% are making. 4o% #an #he#k the )tore*it;rror;vent.te+t property
to see "hat "ent "rong.
:$'m runnin+ my own ser9er bac6"end to deli9er products and 9erify purchases with Apple's
9alidation ser9er. Aow do $ implement this on the client sideB;
(he e+ample appli#ation sho"s tra#king in-app p%r#hases "ith a simple #lient 'ased model. Jo"ever,
advan#ed %sers may "ish to %se their o"n server to tra#k, veri/y, and provide in-app p%r#hase #ontent.
$or more in/ormation on ho" this might 'e implemented, see Apple.s most re#ent do#%mentation. (he
e+tension provides the en#oded re#eipt data yo% need to pass to yo%r server in this #ase, as the
property receipt o/ the StoreKitEvent.PURCHASE_SUCCEEDED event that is dispat#hed a/ter a p%r#hase.
Also( if you are using server-side verification( you may wis to delay te completion of te transaction
on te client until your server as verified te purcase. "o do tis( you may call
StoreKit.storeKit.setManualMode(true) to enable manual verification( ten subse)uently call
StoreKit.storeKit.manualFinishTransation(transation!d) to finis te transaction on te i&$
side after your server as verified it( in te P#*!+A$E,SUCCEEDED or PURCHASE_FA!"ED listeners. "f
you are also using A((le56osted downloadable content, you must *7T call
manualFinishTransation(transation!d) until te download as failed or completed- oterwise
te downloaded content will not be available on te filesystem.
:$ still need helpD Aow can $ +et technical supportB;
4o%r p%r#hase #omes "ith /ree te#hni#al s%pport 'y email E G%st send %s a message at
s%pport&milkmangames.#om . De.re here to helpF 3lease remem'er that...
De.re open d%ring :nited )tates '%siness ho%rs, e+#l%ding :.). Jolidays, Monday-$riday, 3a#i/i# )tandard
(ime. De strive to ans"er all s%pport email "ithin 28 ho%rs 5not in#l%ding "eekends and holidays7 '%t
%s%ally do so m%#h /aster. <emem'er that "e may not 'e in the same time Ione.
3lease remem'er to mention "hi#h e+tension yo%.re having a pro'lem "ith, "hat 10; yo%.re %sing 5s%#h
as .$lash C)?. or .$lash C%ilder 8.?.7, and "hat devi#e yo%.re targeting. 1/ yo%.re e+perien#ing an error
message, please spe#i/y "hat that message is.
.e don/t provide tec support troug blog comments( 0aceboo'( or "witter. Please email us and we/ll be
appy to elp you out1

Das könnte Ihnen auch gefallen