しめ鯖日記

swift, iPhoneアプリ開発, ruby on rails等のTipsや入門記事書いてます

Apple Pay と In-App Purchase の使い分け方を調べてみた

最近Suicaが使えると話題のApple Payについてです。
Apple Payについて最近調べていたところ、アプリ内の課金にも使える事がわかりました。

しかしアプリ内課金はIn App purchaseが既にあるので、その辺りの使い分けをどうしたらいいかを調べてみました。

Apple PayとIn App Purchaseの使い分け

Getting Started with Apple Pay - Apple Developer

It is important to understand the difference between Apple Pay and In-App Purchase. In apps, use Apple Pay to sell physical goods such as groceries, clothing, and appliances. Also use Apple Pay for services such as club memberships, hotel reservations, and tickets for events. On the other hand, use In-App Purchase to sell virtual goods such as premium content for your app and subscriptions for digital content. Coming this fall, websites can use Apple Pay for physical goods purchases as well as virtual goods purchases that will not be consumed within an iOS app.

The Apple Pay Programming Guide provides details on how to use the PassKit framework to integrate Apple Pay. The In-App Purchase Programming Guide provides details on how to use the StoreKit framework to integrate In-App Purchases.

公式ドキュメントを読んだ所、アプリ内で食料品、衣服、家電製品などの物理的な商品を購入する際に使うようです。
アプリ内のプレミアム会員や機能開放などのデジタルコンテンツは今まで通りアプリ内課金を使えば良さそうです。

UITableViewCellEditingStyleでnoneを選んだ時にできる空白スペースを削除する

UITableViewCellで、削除ボタンを出さなくした時のスペースを消す方法です。

内容

UITableViewでは以下のようなメソッドを実装する事で編集中に削除ボタンを出さない事ができます。

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

しかし消すだけだと左側にスペースが残ってしまいます。

f:id:llcc:20160924131603p:plain

shouldIndentWhileEditingRowAtを実装する事でスペースを消す事ができます。

override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

f:id:llcc:20160924131742p:plain

【In-App Purchase】iOSでInvalid Product Identifierが出た時の対処法

アプリ内課金でアイテム情報が取得できなかった時の対処法です。

今回のケースでは、iTunesconnectの「契約/税金/口座情報」を入力する事で解決しました。 入力後30分くらい経ったらプロダクト情報が取れるようになりました。

シンプルなRESTClient、insomniaを試してみる

insomniaというRESTClientを試してみました。

insomnia.rest

アプリはこちらのページからダウンロードしました。

insomnia.rest

起動後画面は下のようなものです。

f:id:llcc:20160921234259p:plain

このようにURL指定でリクエストを送る事ができます。

f:id:llcc:20160921234305p:plain

ベーシック認証・ヘッダー・パラメータなどを自由に付けれるようです。

f:id:llcc:20160921234311p:plain

作成したリクエストは保存する事もできます。

f:id:llcc:20160921234314p:plain

【Swift】呼び出し元のメソッド名を取得する

メソッドの呼び出し元を取得する方法を調べました。

良くある方法はスタックトレースを見る方法です。

class MyClass {
    func originMethod() {
        targetMethod()
    }
    
    func targetMethod() {
        let symbols = NSThread.callStackSymbols()
        print(symbols.count >= 2 ? symbols[1] : "")
    }
}

以下のような形式で出力されるので少し加工が必要です。

1   MyApp                               0x000000010be1f242 _TFC5MyApp7MyClass12originMethodfT_T_ + 18

他にもデフォルト引数で#functionを受け取る方法もあります。

class MyClass {
    func originMethod() {
        targetMethod()
    }
    
    func targetMethod(originMethodName: String = #function) {
        print(originMethodName)
    }
}

こちらだとメソッド名がしっかり出てくれるので扱いやすいです。

targetMethod

参考URL

【Swift】メソッドがどこから呼ばれているかを知るTips - debug identifiers - - Qiita

自作のCocoaPodsライブラリのバージョンを上げる

自作のCocoaPodsライブラリのバージョンを上げる方法です。

まずはpodspecファイルのバージョンを更新します。

Pod::Spec.new do |s|
  s.version = "0.1.4" # ここのバージョンを変える
end

次はそのバージョンのタグを作ってpushします。

git tag 0.1.4
git push --tags

最後にpodコマンドでライブラリの更新をします。

pod trunk push