LoginSignup
42
39

More than 5 years have passed since last update.

swiftとParseでアプリ内課金実装したメモ

Posted at

アプリ内課金実装した際のメモ

  • まずAppleのデベロッパーサイトに行って該当のIdentifiersにIn-App PurchaseがEnableになっているか確認。
    https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action


  • itunes connect > My app > App 内課金 > Create new で課金アイテムを作成


  • Parseのサイトに行ってサインイン > アプリを作成
    https://www.parse.com


  • Install the SDKの指示に従い、SDKをダウンロード。指定されているライブラリをXCodeのGeneral > Linked Frameworks & Librariesから読み込む。


  • ダウンロードしたディレクトリに入っている下記3つのファイルをXcodeのプロジェクト内にドラッグ&ドロップで読み込む
    Bolts.framework
    Parse.framework
    ParseFacebookUtils.framework


  • ヘッダファイル、<プロジェクト名>-Bridging-Header.hを作成し、下記のようにParseライブラリを読み込み、プロジェクト内に配置
    #import <Parse/Parse.h>


  • あとはメソッド二つ書くだけ
AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        Parse.setApplicationId(<Your ApplicationId>, clientKey: <Your ClientKey>)
        PFPurchase.addObserverForProduct(<Item Id>, block: { (transaction: SKPaymentTransaction!) -> Void in
// Do Something
        })

        return true
    }
mainViewController.swift
PFPurchase.buyProduct(<Item Id>, block: { (error: NSError?) -> Void in
                    if error != nil {
                        // error!
                        return
                    }
                    println("You purchased awesome item!")
                })

ハマったところ
AdMobやらなんやらとぶつかって下記のようなエラーに悩まされた
http://stackoverflow.com/questions/15457136/parse-for-ios-errors-when-trying-to-run-the-app

解決策
Build Settings > Linking > Other Linker Flagで -ObjC と設定していたが、
-force_load $(SRCROOT)/GoogleMobileAdsSdkiOS-6.12.0/libGoogleAdMobAds.a
として個別に読み込むように変更した。
FacebookSDKをプロジェクトに追加した。

以上でうまく動くようになりました。


参考

iOS Swift Tutorial: inApp Purchases - Setup and Integration
https://www.youtube.com/watch?v=NMdVZ592ZZE

42
39
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
39