• Dashboard
  • API
  • Guides
  • FAQ
  • iOS > SDK integration

    Push setup

    Setting up the Push

    Since you've generated a new provisioning profile, think about changing your build setting to build with this new provisioning.

    First of all, open your project in Xcode by clicking on it in the sidebar, then click on the Capabilities tab. Make sure Push Notifications is ON, and that both checks are there. If there is a Fix button shown, press it.

    Xcode Capabilities

    Then, you need to add a few lines to your app delegate in order to receive push notifications.

    To ask for the permission to display notifications and register the current device for push, call the method [BatchPush requestNotificationAuthorization] in your application delegate or wherever it is appropriate.

    @import Batch;
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {  
        // Start Batch.
        [Batch startWithAPIKey:@"YOUR_API_KEY"]; 
    
        // Ask for the permission to display notifications
        // The push token will automatically be fetched by the SDK
        [BatchPush requestNotificationAuthorization];
    
        // Alternatively, you can call requestNotificationAuthorization later
        // But, you should always refresh your token on each application start
        // This will make sure that even if your user's token changes, you still get notifications
        // [BatchPush refreshToken];
    
        return YES;
    }
    
    import Batch
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Start Batch.
        Batch.start(withAPIKey: "YOUR_API_KEY")
    
        // Register for push notifications
        BatchPush.registerForRemoteNotifications()
    
        // Alternatively, you can call requestNotificationAuthorization later
        // But, you should always refresh your token on each application start
        // This will make sure that even if your user's token changes, you still get notifications
        // BatchPush.refreshToken();
    
        return true
    }
    

    Note: If you already implement a UNUserNotificationCenterDelegate class, please read the intercepting notifications documentation to properly integrate Batch into it.

    Your first notification

    1. Obtaining your device token

    You can find your device's token using the debug tool or locating the token Batch posts to the Xcode console:

    [Batch] - Push token (Apple Push Production): X
    

    Based on your Provisioning Profile, the token shown in the console will be Development ("Sandbox/Development") or Production ("Production").

    2. Sending a test push

    Go to ⚙ Settings → Push settings, paste your device's token, choose the right environment and click on Save.

    Then, all you have to do is to click on the "Send" button. If you sucessfuly set up the SDK, you will receive a notification on your device.

    Test push iOS

    Troubleshooting
    If you're having trouble sending test notifications, you can check our troubleshooting documentation.

    What's next

    Congratulations on finishing the integration of Batch Push!

    Here are a couple of extra steps you can take before releasing your app: