# General

### Batch sample apps

If you want to see a proper integration of the Batch SDK and to test any of its functionalities, you can take a look at our **sample apps**.

→ [Download the sample app on GitHub](https://github.com/BatchLabs/batchcast-ios)

They are currently written for iOS in both Swift and Objective-C.

### Manual framework integration

{% stepper %}
{% step %}
**Step 1**

First, download the SDK and Include `Batch.xcframework` in your project by dragging and dropping it into the Project Navigator as shown here:

![Project Navigator view](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-71866785ffc272f3b9613ca8392bc11c6249d0ce%2Fproject_navigator_framework.png?alt=media)

Unless you manually copied the XCframework folder into your project's directory, check `Copy items if needed`. Make sure the only checked target is your Application target: extensions should be unchecked.

![Xcode add framework to project](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-7ff0f232637e10d8774957a16b9305dfed31a4f6%2Fxcode_add_main_xcframework.png?alt=media)
{% endstep %}

{% step %}
**Step 2**

Be sure `Batch.xcframework` and `libsqlite3.tbd` are in the **Build Phases** of your application target:

![Link with libraries build phase](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-6453b367c2dd979070f7b326b50170127d95570a%2Flink_with_libraries.png?alt=media)
{% endstep %}

{% step %}
**Step 3**

In order to avoid a link issue when building your application, add `-ObjC -lz` to **Other Linker Flags**, under **Build Settings** of your application target.

![Linker flags](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-21364e9c1a302733689c4b36977d373e8881c003%2Flinker_flags.png?alt=media)

{% hint style="info" %}
You can now proceed with the [integration of the SDK](https://doc.batch.com/developer/sdk/ios/sdk-integration)
{% endhint %}
{% endstep %}
{% endstepper %}

### Generating the .p12 certificate

#### Creating a certificate

Batch servers need to have a certificate in order to communicate with Apple Push Notification Services *(APNS)*. This certificate is generated for an unique Application Identifier *(App ID)*.

{% stepper %}
{% step %}
**Step 1.**

Open your **Keychain application** on your Mac. In the menu bar, select **"Keychain Access" → "Certificate Assistant" → "Request a Certificate From a Certificate Authority…"**

![Keychain](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-836b5204d22010f6d60ccf57233021cd3d28865a%2Fkeychain_request_menu.png?alt=media)

Then, enter your information in the required fields and select **"Saved to disk"**. Save the *"CertificateSigningRequest.certSigningRequest"* file to your Desktop.

![Certificate](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-2ba90bce4295f7ec6bb8962ff2a4aa222fc86626%2Fkeychain_save_request.png?alt=media)
{% endstep %}

{% step %}
**Step 2.**

Head to the [Apple Developer Member center](https://developer.apple.com/account/resources/identifiers/list), open the `Identifiers` section and create a new App ID *(or choose an existing Explicit App ID)* to configure Push Notifications.

![Entitlements](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-47b84435ccc48a003636e235afefe005ce029773%2Fapple_dev_entitlements.png?alt=media)

Scroll down to the Push Notifications section, check it if needed and click configure.

![SSL certificate popup](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-caf144a3b4568242a6ce79db7742b12f20672e7d%2Fapple_dev_certificate_popup.png?alt=media)

Under *"Production SSL Certificate"*, click on **"Create Certificate..."**. The Production certificate can push both sandbox and production environments.

The next screen will ask us to upload the Certificate Signing Request *(CSR)*, which we have created earlier.

![CSR Upload](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-a8eb3cd3ea8ae820f07773bb2a58bc47cf3e32cf%2Fapple_dev_certificate_upload_csr.png?alt=media)

Select **"Choose File…"** and locate the *.certSigningRequest* file on your desktop. Finally, select **"Continue"** and download the generated SSL certificate.

![Generated Certificate](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-393af68d37ab141b2af31c2efa808ff036e1d40b%2Fapple_dev_certificate_download.png?alt=media)
{% endstep %}
{% endstepper %}

#### Generating the .p12 file

Now you have the certificate, you need to have it with its key bundled into a .p12 file format.

{% stepper %}
{% step %}
**Step 1.**

First, add the certificate to your **Keychain** by double clicking on the downloaded SSL certificate.

In Keychain Access, pick the default keychain (`login` on English systems) using the sidebar. Then, click on **"My Certificates"** and find the certificate you just added. It should be called *"Apple Push Services:"*.

{% hint style="info" %}
Certificates called **"Apple Production IOS Push Services"** and **"Apple Development IOS Push Services"** are not supported anymore. Please generate a new Production Certificate
{% endhint %}
{% endstep %}

{% step %}
**Step 2.**

Make sure that the certificate is collapsed (the arrow on the left ( > ) should point to the right).\
Right-click on the certificate, select **"Export Apple Push Services:…"**, and save it as a .p12 file.

![Keychain export menu](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-6b67cc633c8fb81a31d6c12e043652aec56c1348%2Fkeychain_export.png?alt=media)

You will be prompted to enter a password which will be used to protect the exported certificate.

![Keychain export password prompt](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2Fgit-blob-c063d98aa4cc6153bb848551816f08537786b252%2Fkeychain_export_password.png?alt=media)

{% hint style="info" %}
If the Personal Information Exchange (.p12) option is grayed out in the export sheet, make sure *"My Certificates"* is selected in Keychain Access.
{% endhint %}
{% endstep %}

{% step %}
**Step 3.**

Now go to Batch's dashboard → ⚙ **Settings → Channel -> iOS**, and upload your P12 certificate.

![BatchSettings](https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2FCONzy64optYgTQd4dLAO%2Fdashboard_ios_push_settings.png?alt=media\&token=7823b157-bfcc-460a-bc23-90a9b8886c1d)

{% hint style="info" %}
**Troubleshooting: I**f you're having trouble uploading your certificate, you can check our [troubleshooting documentation](https://doc.batch.com/developer/sdk/ios/troubleshooting).
{% endhint %}
{% endstep %}
{% endstepper %}

#### Generating your Provisioning Profile

After creating a new App ID or modifying your existing one, you need to (re)generate your provisioning profile and build with it.

{% stepper %}
{% step %}
**Step 1.**

Go to [Apple Developer website](https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action), then click on **"Provisioning Profiles"** from the iOS Apps section.

Click on the **"+"** button to create a new iOS Provisioning Profile or select an existing one.

{% hint style="info" %}
If you already have one, make sure it has *Push Notifications* in the **Enabled Services** field.
{% endhint %}
{% endstep %}

{% step %}
**Step 2.**

In the Provisioning Profile creation wizard:

* **Select Type:** Choose *"App Store"*.
* **Configure:** Choose the App ID you created before from the drop down and make sure to select your iOS Production certificate.
* **Generate**: Choose a name for this provisioning profile, such as "Batch Push App Profile" and select *"Generate"*

Then download the generated provisioning profile from the next screen by selecting the **"Download"** button.
{% endstep %}

{% step %}
**Step 3.**

Install the profile by double-clicking on the downloaded file.

Your new provisioning profile should appear in the Provisioning Profiles section in your Xcode settings under the **"Accounts"** section. Make sure that your developer certificate is installed in your Keychain.

{% hint style="info" %}
Batch Push campaigns are sent to both the apps built with your **Development** and the **Distribution** provisioning profile.
{% endhint %}
{% endstep %}
{% endstepper %}

### Problems with your application delegate

If Batch tells you that it was unable to automatically integrate with your application delegate, it's probably because there is a conflict with another SDK.

Try calling `[BatchSDK startWithAPIKey:]` earlier in your application delegate.
