Integration

The latest version of the Teak iOS SDK is always available at:

Dependencies

The following frameworks are required by Teak

  • AdSupport.framework

  • AVFoundation.framework

  • ImageIO.framework

  • Services.framework

  • StoreKit.framework

  • UserNotifications.framework

  • CoreGraphics.framework

  • UIKit.framework

  • SystemConfiguration.framework

Dependencies as compiler flags
-framework AdSupport -framework AVFoundation -framework CoreServices
  -framework StoreKit -framework UserNotifications -framework ImageIO
  -framework CoreGraphics -framework UIKit -framework SystemConfiguration

Edit Info.plist

Add the following keys and values to your Info.plist file:

Info.plist
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>teakYOUR_TEAK_APP_ID</string>
        </array>
    </dict>
</array>
Replace YOUR_TEAK_APP_ID with your game’s value.

This will add the teak123456:// URL scheme in order for deep link fallbacks to work properly.

Edit Entitlements

YourApp.entitlements
<key>com.apple.developer.associated-domains</key>
<array>
    <string>applinks:YOUR_SHORTLINK_DOMAIN.jckpt.me</string>
</array>
Replace YOUR_SHORTLINK_DOMAIN with your game’s subdomain.

Your Teak Shortlink Domain can be found in the Settings for your app on the Teak dashboard.

Initialize Teak

Initialize Teak in your main.m file using initForApplicationId:withClass:andApiKey:

Initializing Teak
// Step 1:
// Import Teak into the main.m file to use the initialization method.
#import <Teak/Teak.h>

int main(int argc, char* argv[]) {
  @autoreleasepool {
    // Step 2:
    // Initialize Teak inside the @autoreleasepool but before
    // UIApplicationMain() is called.
    [Teak initForApplicationId:@"YOUR_TEAK_APP_ID"
                     withClass:[AppDelegate class]
                     andApiKey:@"YOUR_TEAK_API_KEY"];

    // Continue to our AppDelegate.m file for the next steps.

    return UIApplicationMain(argc, argv, nil,
                             NSStringFromClass([AppDelegate class]));
  }
}
You must initialize Teak inside the @autoreleasepool but before UIApplicationMain() is called.
Replace YOUR_TEAK_APP_ID and YOUR_TEAK_API_KEY with the values for your game.

Teak also exposes this functionality via a C API:

extern void Teak_Plant(Class appDelegateClass,
                       NSString* appId,
                       NSString* appSecret);

Identify User, and Add Observers

As soon as your game knows how it will identify the current user in your own backend, you should tell Teak that identifyer.

Teak will wait until a user is identified before it will send NSNotificationCenter notifications to inform you about events (covered later).

Remaining Integration
// Step 3:
// Import Teak into your UIApplicationDelegate implementation.
#import <Teak/Teak.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application
        didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

  // Register a deep link that opens the store to the specific SKU
  // Routes use pattern matching to capture variables. Variables are
  // prefixed with ':', so ':sku' will create a key named 'sku' in the
  // dictionary passed to the block.
  //
  // Name and Description are optional, but will show up in the
  // Teak Dashboard to help identify the deep link
  [TeakLink registerRoute:@"/store/:sku"
                     name:@"Store SKU"
              description:@"Opens IAP screen for the specified SKU"
                    block:^(NSDictionary* _Nonnull params) {
                      NSLog(@"%@", params);
                      NSLog(@"SKU: %@", params[@"sku"]);
                    }];

  // Step 4:
  // In your game, you will want to use the same user id that
  // you use in your database.
  //
  // These user ids should be unique, no two players should
  // have the same user id.
  //
  // Call identifyUser as soon as you know the user id
  // of the current player.
  [[Teak sharedInstance] identifyUser:ASSIGNED_USER_ID];

  // Step 5:
  // Tell Teak that you want to be notified when your game
  // has been launched via a Push Notification.
  //
  // See the bottom of this file for an example of a handler function.
  [[NSNotificationCenter defaultCenter]
        addObserver:self
           selector:@selector(handleTeakNotification:)
               name:TeakNotificationAppLaunch
            object:nil];

  return YES;
}

// This is an example of a handler function that will be called
// when your app is launched from a Push Notification.
- (void)handleTeakNotification:(NSNotification*)notification {
  NSLog(@"TEAK TOLD US ABOUT A NOTIFICATION, THANKS TEAK!");
}

@end