> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/classic-push-provisioning/ja/ysuksu/xpayworettohenopusshupurobijoningu/ios/pusshupurobijoningu.md).

# プッシュプロビジョニング

## ステップ1: 次を表示する **ウォレットに追加** ボタン <a href="#step-1-showing-the-add-to-wallet-button" id="step-1-showing-the-add-to-wallet-button"></a>

エンドユーザーが最初にイシュアアプリケーションを起動したとき、特定のカードに対して次を表示するか非表示にするかを判断する必要があります。 **Apple Walletに追加** 特定のカードのボタン。

できるだけ早く、エンドユーザーがiPhoneを持っているか、Apple WatchとペアリングされたiPhoneを持っているかを判定します。

次に、このペアリング状態をPush Provisioning SDKと組み合わせて `getToken` APIの結果を使用して、次を表示するか非表示にするかを決定します。 **Apple Walletに追加** ボタン。

{% tabs %}
{% tab title="Swift" %}

```swift
import WatchConnectivity

class ViewController: UIViewController, TPCSDKProvisionDelegate, WCSessionDelegate {    
    // TPC関数を呼び出す前に isWatchPaired 値を保存するため
    var isWatchPaired = false

    override func viewDidLoad() {
        super.viewDidLoad()
        // ビューの読み込み後に追加のセットアップを行います。
        if WCSession.isSupported() {
            let session = WCSession.default
            session.delegate = self
            session.activate()
        }
    }
    
    // MARK: WCSessionDelegate
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
        if error != nil {
            // エラーを処理する
        } else if activationState == .activated && session.isPaired {
            isWatchPaired = true
        }
    }
    
    func sessionDidBecomeInactive(_ session: WCSession) {
        // sessionDidBecomeInactive を処理する
        isWatchPaired = false
    }
    
    func sessionDidDeactivate(_ session: WCSession) {
        // sessionDidDeactivate を処理する
        isWatchPaired = false
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
#import <WatchConnectivity/WatchConnectivity.h>

@interface ViewController : UIViewController <TPCSDKProvisionDelegate, WCSessionDelegate>
@property BOOL isWatchPaired;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([WCSession isSupported]) {
        WCSession* session = [WCSession defaultSession];
        session.delegate = self;
        [session activateSession];
    }
}

// MARK: WCSessionDelegate
- (void)session:(nonnull WCSession *)session activationDidCompleteWithState:(WCSessionActivationState)activationState error:(nullable NSError *)error { 
    if (error != nil) {
        // エラーを処理する
    } else if (activationState == WCSessionActivationStateActivated && session.isPaired == TRUE)  {
        _isWatchPaired = TRUE;
    }
}

- (void)sessionDidBecomeInactive:(nonnull WCSession *)session { 
    // sessionDidBecomeInactive を処理する
    _isWatchPaired = FALSE;
}

- (void)sessionDidDeactivate:(nonnull WCSession *)session { 
    // sessionDidDeactivate を処理する
    _isWatchPaired = FALSE;
}
```

{% endtab %}
{% endtabs %}

次に、 `getToken` APIを呼び出して結果を更新します。

> <i class="fa-info-circle">:info-circle:</i>
>
> #### 注意 <a href="#note" id="note"></a>
>
> 次を参照してください [PKAddPassButton](https://developer.apple.com/documentation/passkit/pkaddpassbutton) イシュアアプリケーションでボタンを使用するためのガイドライン。 **Apple Walletに追加** ボタンをイシュアアプリケーションで使用するためのガイドライン。

次は iOS SDK 2.0.0 およびそれ以前に適用されます。

{% tabs %}
{% tab title="Swift" %}

```swift
func getCardDigitizationResultWithFundingCardWithSchemeAndPayload() {
    let scheme = CardScheme.Mastercard
    let payload = "PKCS7 encrypted PAN"
    
    let card = FundingCard(scheme: scheme,
                            encryptedPayload: payload)
    
    TPCSDK.getCardDigitizationResult(card: card) { [weak self]
        (primaryAccountIdentifier, sdkResult, error) in
        self?.updateUI(for: sdkResult, sdkError: error)
    }
  }

  func getCardDigitizationResultWithPrimaryAccountIdentifier() {
    let primaryAccountIdentifier = "primaryAccountIdentifier"

    TPCSDK.getCardDigitizationResult(primaryAccountIdentifier: primaryAccountIdentifier) { [weak self]
        (primaryAccountIdentifier, sdkResult, error) in
        self?.updateUI(for: sdkResult, sdkError: error)
    }
  }

  func getCardDigitizationResultWithPrimaryAccountNumberSuffix() {
      let scheme = "SCHEME" // VISA, MASTERCARD, AMEX, DISCOVER
      let encryptedPayload = "PKCS7 encrypted PAN"
      let primaryAccountNumberSuffix = "Last 4 Digits of PAN"

      let card = FundingCard(schemeString: scheme,
              encryptedPayload: encryptedPayload)

      TPCSDK.getCardDigitizationResult(card: card, primaryAccountNumberSuffix: primaryAccountNumberSuffix) { [weak self]
          (primaryAccountIdentifier, sdkResult, error) in
          self?.updateUI(for: sdkResult, sdkError: error)
      }
  }

func updateUI(for sdkResult: CardDigitizationResult?, sdkError: Error?) {
    if let error = sdkError {
      // エラーを処理する
    } else if let sdkResult = sdkResult {
      if sdkResult.localPKPass?.secureElementPass?.passActivationState == .requiresActivation {
        // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
        // iPhone上でカードのアクティベーションが保留中です。
      } else if sdkResult.remotePKPass?.secureElementPass?.passActivationState == .requiresActivation {
        // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
        // Apple Watch上でカードのアクティベーションが保留中です。
      } else if sdkResult.localPKPass != nil && sdkResult.remotePKPass == nil {
        if isWatchPaired {
          // Apple Watch用の「Apple Walletに追加」ボタンを表示します。
        } else {
          // 「Apple Walletに追加」ボタンを非表示にします。
        }
      } else if sdkResult.localPKPass == nil {
        // 「Apple Walletに追加」ボタンを表示します。
      } else if sdkResult.localPKPass != nil && sdkResult.remotePKPass != nil {
        // カードは既にプロビジョニングされています。「Apple Walletに追加」ボタンを非表示にします。
      }
    }
  }
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
- (void)getCardDigitizationResultWithFundingCardWithSchemeAndPayload {
    CardScheme scheme = CardSchemeMastercard;
    NSString* payload = @"PKCS7 encrypted PAN";

    FundingCard* card = [[FundingCard alloc] initWithScheme:scheme
                                            encryptedPayload:payload];

    [TPCSDK getCardDigitizationResultWithCard:card
                     primaryAccountIdentifier:nil
                   primaryAccountNumberSuffix:nil
                                   completion:^(NSString* primaryAccountIdentifier, CardDigitizationResult* _Nullable sdkResult, NSError* _Nullable error) {
        [self updateUIForResult:sdkResult sdkError:error];
    }];
}

- (void)getCardDigitizationResultWithPrimaryAccountIdentifier {
    NSString* primaryAccountIdentifier = @"primaryAccountIdentifier";

    [TPCSDK getCardDigitizationResultWithCard:nil
                     primaryAccountIdentifier:primaryAccountIdentifier
                   primaryAccountNumberSuffix:nil
                                   completion:^(NSString* primaryAccountIdentifier, CardDigitizationResult* _Nullable sdkResult, NSError* _Nullable error) {
        [self updateUIForResult:sdkResult sdkError:error];
    }];
}

- (void)getCardDigitizationResultWithPrimaryAccountNumberSuffix {
    CardScheme scheme = CardSchemeMastercard;
    NSString* payload = @"PKCS7 encrypted PAN";
    NSString* primaryAccountNumberSuffix = @"Last 4 Digits of PAN";

    FundingCard * card = [[FundingCard alloc] initWithScheme:scheme
                                            encryptedPayload:payload];

    [TPCSDK getCardDigitizationResultWithCard:nil
                     primaryAccountIdentifier:nil
                   primaryAccountNumberSuffix:primaryAccountNumberSuffix
                                   completion:^(NSString* primaryAccountIdentifier, CardDigitizationResult* _Nullable sdkResult, NSError* _Nullable error) {
        [self updateUIForResult:sdkResult sdkError:error];
    }];
}

- (void)updateUIForResult:(CardDigitizationResult* _Nullable)sdkResult sdkError:(NSError * _Nullable) error {
    if (error != nil ) {
        // エラーを処理する
    } else if(sdkResult != nil){
        if ( sdkResult.localPKPass.secureElementPass.passActivationState == PKSecureElementPassActivationStateRequiresActivation ) {
            // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
            // iPhone上でカードのアクティベーションが保留中です。
        } else if ( sdkResult.remotePKPass.secureElementPass.passActivationState == PKSecureElementPassActivationStateRequiresActivation ) {
            // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
            // Apple Watch上でカードのアクティベーションが保留中です。
        } else if ( sdkResult.localPKPass != nil && sdkResult.remotePKPass == nil ) {
            if ( [self isWatchPaired] ) {
                // Apple Watch用の「Apple Walletに追加」ボタンを表示します。
            } else {
                // 「Apple Walletに追加」ボタンを非表示にします。
            }
        } else if ( sdkResult.localPKPass == nil ) {
            // 「Apple Walletに追加」ボタンを表示します。
        } else if ( sdkResult.localPKPass != nil && sdkResult.remotePKPass != nil ) {
            // カードは既にプロビジョニングされています。「Apple Walletに追加」ボタンを非表示にします。
        }
    }
}
```

{% endtab %}
{% endtabs %}

次は iOS SDK 2.1.0 以降に適用されます。

{% tabs %}
{% tab title="Swift" %}

```swift
func getTokenWithInputByLast4() {
    // 物理カード（FPAN）の下4桁。
    let last4 = "1234" 
    let tokenInput = GetTokenInput(last4: last4)
    TPCSDK.getToken(input: tokenInput) { [weak self]
        (localPass, remotePass, error) in
        self?.updateUI(for: localPass, remotePass: remotePass, sdkError: error)
    }
}

// - Since: 2.3.0
func getTokenWithInputBySerialNumber() {
    // Apple Payにより提供されるシリアル番号。
    let serialNumber = "Serial number"
    let tokenInput = GetTokenInput(serialNumber: serialNumber)
    TPCSDK.getToken(input: tokenInput) { [weak self]
        (localPass, remotePass, error) in
        self?.updateUI(for: localPass, remotePass: remotePass, sdkError: error)
    }
}

func updateUI(for localPass: PKPass?, remotePass: PKPass?, sdkError: Error?) {
    if let error = sdkError {
        // エラーを処理します。
    } else {
        if localPass?.secureElementPass?.passActivationState == .requiresActivation {
            // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
            // iPhone上でカードのアクティベーションが保留中です。
        } else if remotePass?.secureElementPass?.passActivationState == .requiresActivation {
            // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
            // Apple Watch上でカードのアクティベーションが保留中です。
        } else if localPass != nil && remotePass == nil {
            if isWatchPaired {
                // Apple Watch用の「Apple Walletに追加」ボタンを表示します。
            } else {
                // 「Apple Walletに追加」ボタンを非表示にします。
            }
        } else if localPass == nil {
            // 「Apple Walletに追加」ボタンを表示します。
        } else if localPass != nil && remotePass != nil {
            // カードは既にプロビジョニングされています。「Apple Walletに追加」ボタンを非表示にします。
        }
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
- (void)getTokenWithInputByLast4 {
    // 物理カード（FPAN）の下4桁。
    NSString *last4 = @"1234";

    GetTokenInput *tokenInput = [[GetTokenInput alloc] initWithLast4:last4];

    [TPCSDK getTokenWithInput:tokenInput completion:^(PKPass *_Nullable localPass, PKPass *_Nullable remotePass, NSError *_Nullable error) {
        [self updateUIForLocalPass:localPass remotePass:remotePass sdkError:error];
    }];
}

// - Since: 2.3.0
- (void)getTokenWithInputBySerialNumber {
    // Apple Payにより提供されるシリアル番号。
    NSString *serialNumber = @"Serial number";

    GetTokenInput *tokenInput = [[GetTokenInput alloc] initWithSerialNumber:serialNumber];

    [TPCSDK getTokenWithInput:tokenInput completion:^(PKPass *_Nullable localPass, PKPass *_Nullable remotePass, NSError *_Nullable error) {
        [self updateUIForLocalPass:localPass remotePass:remotePass sdkError:error];
    }];
}

- (void)updateUIForLocalPass:(PKPass *_Nullable)localPass remotePass:(PKPass *_Nullable)remotePass sdkError:(NSError *_Nullable)error {
    if (error != nil) {
        // エラーを処理します。
    } else {
        if (localPass != nil && localPass.secureElementPass.passActivationState == PKSecureElementPassActivationStateRequiresActivation) {
            // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
            // iPhone上でカードのアクティベーションが保留中です。
        } else if (remotePass != nil && remotePass.secureElementPass.passActivationState == PKSecureElementPassActivationStateRequiresActivation) {
            // アクティベートアクションについてはトークンライフサイクル管理を参照してください。 
            // Apple Watch上でカードのアクティベーションが保留中です。
        } else if (localPass != nil && remotePass == nil) {
            if ([self isWatchPaired]) {
                // Apple Watch用の「Apple Walletに追加」ボタンを表示します。
            } else {
                // 「Apple Walletに追加」ボタンを非表示にします。
            }
        } else if (localPass == nil) {
            // 「Apple Walletに追加」ボタンを表示します。
        } else if (localPass != nil && remotePass != nil) {
            // カードは既にプロビジョニングされています。「Apple Walletに追加」ボタンを非表示にします。
        }
    }
}
```

{% endtab %}
{% endtabs %}

> <i class="fa-exclamation-circle">:exclamation-circle:</i>
>
> #### 注意 <a href="#caution" id="caution"></a>
>
> * プロビジョニング後もカードが「NOT\_DIGITIZED」と表示される場合は、イシュアアプリケーションがTSPポータルで正しく構成されているか確認してください。
> * その `TPCSDK.isCardDigitized` APIは非推奨で推奨されません。代わりに次のAPIを使用してください。 `getToken` APIを使用してください。なお、 `isCardDigitized` APIはカードがアクティベーション保留中か、iPhone上かApple Watch上かを示しません。

## ステップ2: カードをプロビジョニングする <a href="#step-2-provisioning-a-request" id="step-2-provisioning-a-request"></a>

プロビジョニングデリゲートはプロビジョニング完了後に [PKPass](https://developer.apple.com/documentation/passkit/pkpass) を返します。それを使用してカードのデジタル化状況を確認します。デリゲートが `nil`を返す場合、SDKはエラーも返します。

PKPass クラスを使用する前に、PassKit.framework をプロジェクトに追加してください。

> <i class="fa-exclamation-circle">:exclamation-circle:</i>
>
> #### 警告 <a href="#warning" id="warning"></a>
>
> このAPIを呼び出す前に、イシュアアプリケーションにPush Provisioning権限を追加する必要があります。そうしないと、APIはエラーを返します。権限を取得するには次の手順に従ってください。 [Push Provisioning Access ガイドライン](/classic-push-provisioning/ja/gaido/sdkno/ios.md).

> <i class="fa-info-circle">:info-circle:</i>
>
> 次のAPIを使用して取得します。 `getToken` ローカルPKPass `または` リモートPKPass `。いずれかが`でない場合、PKSecureElementPass オブジェクトの `または` リモートPKPass `。いずれかが` primaryAccountIdentifier `nil`プロパティにアクセスします。取得した `を` provision [`APIに渡します。`](https://developer.apple.com/documentation/passkit/pksecureelementpass) Visa、Mastercard、Amex、Discover の標準スキーム列挙値を使用したプロビジョニング `を` func onProvisionCompletion(pass: PKPaymentPass?, error: Error?) { `if let error = error {` if let tpcError = error as? TPCError {

### // TPCError を処理する <a href="#provisioning-with-standard-scheme-enum-types-for-visa-mastercard-amex-and-discover" id="provisioning-with-standard-scheme-enum-types-for-visa-mastercard-amex-and-discover"></a>

{% tabs %}
{% tab title="Swift" %}

```swift
let provisionError = error as NSError
    if provisionError.domain == PKPassKitErrorDomain  {
      // Apple からのエラー
          // https://developer.apple.com/documentation/passkit/pkaddpaymentpasserror
      } else {
          switch provisionError.code {
          case PKAddPaymentPassError.unsupported.rawValue:
              print("アプリはApple Payにカードを追加できません。")
              case PKAddPaymentPassError.userCancelled.rawValue:
              print("ユーザーがApple Payへのカード追加の要求をキャンセルしました。")
                  case PKAddPaymentPassError.systemCancelled.rawValue:
                      print("システムがApple Payへのカード追加の要求をキャンセルしました。")
                  default:
                      break
                  } else if let pass = pass {
                      // pass オブジェクトで成功した結果を処理する
                  func provision() {
                      let suffix = "1234"
              }
          }
      }
    let cardholderName = "John Doe"
        let code = "code"
    }
  }
  
  TPCSDK.provision(fromController: self,
    primaryAccountSuffix: suffix,
    cardholderName: cardholderName,
    let scheme = CardScheme.Mastercard
    let payload = "PKCS7 encrypted PAN"
    scheme: scheme,
    
    encryptedPayload: payload,
                     authorizationCode: code,
                     provisionDelegate: self)
                     - (void)onProvisionCompletionWithPass:(PKPaymentPass * _Nullable)pass
                     error:(NSError * _Nullable)error {
                     // TODO: プロビジョニングに問題があります
                     // 詳細は Swift コードを参照してください
  }
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
- (void)provision {
                                NSString * suffix = @"1234";
    if (error != nil) {
        NSString * cardholderName = @"John Doe";
        NSString * scheme = CardSchemeMastercard;
    }
}

NSString * payload = @"PKCS7 encrypted PAN";
  NSString * code = @"code";
  [TPCSDK provisionFromController:self
  primaryAccountSuffix:suffix
  cardholderName:cardholderName
  scheme:scheme

  encryptedPayload:payload
             authorizationCode:code
                   provisionDelegate:self];
                           スキーム文字列（標準）でのプロビジョニング
                 let productId = "productId" // 国内スキームにのみ適用されます。これは金融機関のカード管理システムから取得できます。
                schemeString: scheme,
                productId: productId,
}
```

{% endtab %}
{% endtabs %}

### primaryAccountIdentifier:primaryAccountIdentifier, <a href="#provisioning-with-a-scheme-string---standard" id="provisioning-with-a-scheme-string---standard"></a>

{% tabs %}
{% tab title="Swift" %}

```swift
let provisionError = error as NSError
    if provisionError.domain == PKPassKitErrorDomain  {
      // Apple からのエラー
          // https://developer.apple.com/documentation/passkit/pkaddpaymentpasserror
      } else {
          switch provisionError.code {
          case PKAddPaymentPassError.unsupported.rawValue:
              print("アプリはApple Payにカードを追加できません。")
              case PKAddPaymentPassError.userCancelled.rawValue:
              print("ユーザーがApple Payへのカード追加の要求をキャンセルしました。")
                  case PKAddPaymentPassError.systemCancelled.rawValue:
                      print("システムがApple Payへのカード追加の要求をキャンセルしました。")
                  default:
                      break
                  } else if let pass = pass {
                      // pass オブジェクトで成功した結果を処理する
                  func provision() {
                      let suffix = "1234"
              }
          }
      }
    let cardholderName = "John Doe"
        let code = "code"
    }
  }
  
  TPCSDK.provision(fromController: self,
    primaryAccountSuffix: suffix,
    cardholderName: cardholderName,
    let scheme = "SCHEME" // VISA, MASTERCARD, AMEX, DISCOVER
    let payload = "PKCS7 encrypted PAN"
    scheme: scheme,
    NSString * scheme = @"SCHEME"; // VISA, MASTERCARD, AMEX, DISCOVER
    let primaryAccountIdentifier = "primaryAccountIdentifier"
    
    encryptedPayload: payload,
                     authorizationCode: code,
                     provisionDelegate: self)
                     NSString * productId = @"productId"; // 国内スキームにのみ適用されます。これは金融機関のカード管理システムから取得できます。
                     error:(NSError * _Nullable)error {
                     // TODO: プロビジョニングに問題があります
                     NSString * primaryAccountIdentifier = @"primaryAccountIdentifier";
                     schemeString:scheme
                     // 詳細は Swift コードを参照してください
  }
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
- (void)provision {
                                NSString * suffix = @"1234";
    if (error != nil) {
        NSString * cardholderName = @"John Doe";
        NSString * scheme = CardSchemeMastercard;
    }
}

NSString * payload = @"PKCS7 encrypted PAN";
  NSString * code = @"code";
  [TPCSDK provisionFromController:self
  productId:productId
  cardholderName:cardholderName
  scheme:scheme
  schemeString:scheme
  productId:productId

  encryptedPayload:payload
             authorizationCode:code
                   provisionDelegate:self];
                     schemeString:scheme
                 let productId = "productId" // 国内スキームにのみ適用されます。これは金融機関のカード管理システムから取得できます。
                schemeString: scheme,
                        productId:productId
         primaryAccountIdentifier:primaryAccountIdentifier                
                productId: productId,
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/classic-push-provisioning/ja/ysuksu/xpayworettohenopusshupurobijoningu/ios/pusshupurobijoningu.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
