Prerequisites: Authentication · Connect your app to Mobile Sync
We've created a sample app that you can use to check how app switching works. The sample app uses the App Switch Kit and follows the content in our guides.
Important: The sample app is for reference and testing only. Don't use it in production and don't use any live card details. For a list of test card details that you can use, go to Test cards.
The sample app has the following sections:
| Section | Description |
|---|---|
| Target | Select the build of Mobile Sync to switch to. A check mark means that the build is installed on your iPhone. |
| Mobile Sync | Pair the sample app with Mobile Sync, or unpair it. The section shows whether the app is paired. |
| Gateway | Select the gateway that the sample app sends requests to. The section shows your processing terminal ID and a masked version of your Payroc API key, which the app reads from Credentials.json. |
| Transaction | Enter the amount, select the entry method, and add a tax or a tip. |
| Buttons | Select Pay to take a sale, or Capture signature to capture a signature. If the app can't confirm the result, Check status appears. |
Before you begin
Make sure that you've downloaded the App Switch Kit and extracted the contents. For more information, go to Download the App Switch Kit.
Make sure that you have the following:
- Xcode 26 or later.
- An iPhone that runs iOS 18.6 or later.
- Mobile Sync UAT app on the same iPhone as the sample app.
- An Apple Developer account that you can use to sign the sample app.
- Your processing terminal ID, your Payroc API key, and your Mobile Sync API key. We sent you these when you signed up with us. You use the Mobile Sync API key to set up Mobile Sync UAT.
Note: You don't need the Tap to Pay on iPhone entitlement to run the sample app. Mobile Sync reads the card, so Apple's entitlement applies to Mobile Sync and not to your app.
Integration steps
Step 1. Open the project
In the folder that you extracted, open AppSwitchingSample/AppSwitchingSample.xcworkspace in Xcode. The workspace links the App Switch Kit as a local Swift package, so you don't need to install anything else.
The folder contains the following items:
| Folder or file | Contents |
|---|---|
AppSwitchKit/ | The App Switch Kit as a Swift package. |
AppSwitchingSample/ | The sample app. |
docs/ | The kit's integration guide and API reference, as a DocC archive and a website. |
Step 2. Configure signing
The sample app doesn't include a signing identity, so you must set your own team and bundle identifier before you build.
In Xcode, complete the following steps:
- Select the AppSwitchingSample target, and then open the Signing & Capabilities tab.
- For Team, select your Apple Developer team.
- For Bundle Identifier, replace
com.example.appswitchingsamplewith a unique identifier that is registered to your account, for example,com.yourcompany.appswitchingsample.
Step 3. Add your credentials
The sample app reads your processing terminal ID and API keys for our gateway from a Credentials.json file when it runs. Each time you change the file, rebuild the app so that it includes the new values.
To add your credentials, complete the following steps:
- Open
AppSwitchingSample/AppSwitchingSample/Credentials.json. - Replace the placeholders with your own values.
{
"terminalId": "YOUR_TERMINAL_ID",
"payrocAPIKey": "YOUR_PAYROC_API_KEY",
"merchantAPIKey": "YOUR_MERCHANT_API_KEY"
}
| Key | Value |
|---|---|
terminalId | Your processing terminal ID. |
payrocAPIKey | Your Payroc API key. |
merchantAPIKey | Your API key for the Merchant API. Add a value only if you use the Merchant API. |
Important: Never commit this file to source control with real values. The sample app shows only a masked version of your Payroc API key. The file doesn't contain your Mobile Sync API key.
Step 4. Run a test sale
- Connect your iPhone to your Mac.
- In Xcode, select your iPhone as the run destination.
- Select Run.
- In the Target section, select the build of Mobile Sync that you installed:
- Payroc (UAT) - UAT build of Mobile Sync.
- Payroc (Release) - Mobile Sync from the App Store. The sample app sends requests to our test environment, so this build works only after you change the gateway client to our production environment.
- In the Mobile Sync section, select Pair with Mobile Sync. Mobile Sync opens and returns to the sample app, and the sample app shows the Paired with Mobile Sync message. After you pair, the section shows Paired and a masked reader identifier.
- In the Gateway section, check that the dialect matches your terminal and that your processing terminal ID appears. If an error appears here instead, go to Troubleshooting.
- In the Transaction section, enter an amount, and then select one of the following entry methods:
- Device read - Tap a card.
- Manual entry - Manually enter the card details.
- Device read or manual entry - Tap a card or manually enter the card details.
- Select Pay. Mobile Sync opens and shows the sale.
- Tap a test card on the iPhone or enter the card details manually. Mobile Sync takes the payment and returns to the sample app.
If the sale is successful, the sample app gets the result from our gateway and shows the Status and Receipt sections.
Find the code in the sample app
Use the following files to check how the sample app does each task in these guides:
| File | What it contains |
|---|---|
PaymentViewModel.swift | Pairing, sales, signature capture, status checks, and error handling. |
ContentView.swift | The screen and the messages that the app shows to the merchant. |
KnownReceiverTarget.swift | The URL scheme for each build of Mobile Sync. |
Gateway/Credentials.swift | The code that reads Credentials.json. |
Troubleshooting
| Message | Cause | What to do |
|---|---|---|
| Mobile Sync isn't installed | The build of Mobile Sync that you selected isn't on the iPhone. | Install Mobile Sync, or in Target, select the build that you have. |
| Mobile Sync isn't set up | Mobile Sync is new or was reset. | Select Pair with Mobile Sync. |
| Mobile Sync is in Standalone mode | Mobile Sync isn't in Payroc Cloud mode. | In the App settings in Mobile Sync, change the mode. |
| Re-pair with Mobile Sync? | Our gateway doesn't recognize the reader identifier. | Select Re-pair. |
| Payment failed | The sale was canceled, failed, or timed out. | Read the message from our gateway. |
| No Credentials.json in the app bundle | The file is missing, or it isn't valid, or it doesn't contain an API key for the gateway that you selected. | Fix the file, and then rebuild the app. |
For more information about errors, go to Handle errors.