Page tree
Skip to end of metadata
Go to start of metadata

HyprMediate also supports CocoaPods! If you use CocoaPods in your project, please email us at cocoapods@hyprmx.com and we’ll send you those instructions instead. Otherwise, please follow the instructions below. 

Upgrading from HyprMediate iOS 2.5 to 2.6

Remove the HyprMediate.framework. Click 'Move to Trash' when removing.

Drag and drop the new version of the HyprMediate.framework (available in the SDK disk image) file into your Xcode project. Select "copy items if needed" and "create groups" when prompted.

Verify Target Membership

  1. Select HyprMediate.framework in the Project Navigation tab.

2. From the File inspector tab, ensure that it has been added to your Main Application's build target in the "Target Membership" pane.

Make sure HyprMediate.framework and libxml2.tbd are both listed in linked frameworks for your target.

App Transport Security

Ensure that your ATS (App Transport Security) settings are as described in the ATS section below (those have not changed from 2.5).

Privacy Controls

Add or confirm that info.plist contains the following privacy plist keys (these have not changed from 2.5):

  • 'Privacy - Photo Library Additions Usage Description' (NSPhotoLibraryAddUsageDescription)
  • 'Privacy - Photo Library Usage Description' (NSPhotoLibraryUsageDescription) 
  • 'Privacy - Calendars Usage Description' (NSCalendarsUsageDescription)

For more information, see the Privacy Controls section below.

Passing User Consent Status to HyprMarketplace (Optional)

HyprMediate currently supports passing the user's consent status to the HyprMarketplace SDK only. Please review the relevant 3rd-party ad providers' guidelines for how to pass consent status to their SDKs.

If you wish to set the user's consent status, use the following API after you initialize the SDK. 

// HyprConsentStatus can be one of CONSENT_STATUS_UNKNOWN, CONSENT_GIVEN, or CONSENT_DECLINED. If you don't have consent status for the user, you can set this to CONSENT_STATUS_UNKNOWN, which is also the default.
[HyprMX setConsentStatus:<HyprConsentStatus>];

 

That's it! You're up and running with the latest version of the HyprMediate SDK.


Integrating the SDK

  • Drag and drop the HyprMediate.framework (available in the SDK disk image) file into your Xcode project, making sure that the files are copied and not just referenced.  
  • Verify Target Membership

    1. Select HyprMediate.framework in the Project Navigation tab.

    2. From the File inspector tab, ensure that it has been added to your Main Application's build target in the "Target Membership" pane.

     

  • Visit your project's Build Phases, open "Link Binary with Libraries" and add libxml2.tbd
  • Make sure that HyprMediate.framework is listed.
  • Find the key "Other Linker Flags" in the "Linking" section of your project's build settings. For that key, add the value -ObjC. Make sure to select "Debug", "Release", and "Test" within "Other Linker Flags". 


App Transport Security

Apple has put on hold their efforts to enforce ATS (App Transport Security) settings, so many developers are simply turning it off. In order to do so, add the App Transport Security dictionary key below to your Info.plist.

	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>

Your Info.plist will look like this after adding this key: 

If you prefer to enable ATS, you must add the three App Transport Security dictionary keys below to your Info.plist to ensure HyprMediate operates properly.

	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	    <key>NSAllowsArbitraryLoadsInWebContent</key>
	    <true/>       
	    <key>NSAllowsArbitraryLoadsForMedia</key>
	    <true/>       
	</dict>

Your Info.plist will look like this after adding these keys:

Privacy Controls

iOS requires that the use of a user's camera, calendar, photo library, etc. be declared by advertisers in the plist. Please add all of the following entries to your app's plist.

<key>NSCalendarsUsageDescription</key>
<string>${PRODUCT_NAME} requests access to the Calendar</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>${PRODUCT_NAME} requests access to the Photo Library</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>${PRODUCT_NAME} requests write access to the Photo Library</string>

Configuration

Import HyprMediate into the file(s) you wish to use it in by including the following statement: 

 #import <HyprMediate/HYPRMediate.h>


To initialize HyprMediate, use the following code snippet. If you're in AppDelegate.m, we recommend placing it in the didFinishLaunchingWithOptions: method, since that method is called when your app starts.

[HYPRMediate initialize: hyprAPIToken userId: hyprUserId];


Please initialize HyprMediate as soon as possible (i.e. when your application is loading) so preloading will start immediately. We recommend initializing in the AppDelegate.m file.

Your app's API token can be found in App Configuration settings on the HyprMediate Waterfall page. Replace hyprAPIToken with an NSString of that token. 

 

  

 

Replace the hyprUserId parameter with any identifier that is static for each user. The hyprUserId is a unique identifier supplied by your application and should be static for each user across sessions. Your hyprUserId should not contain any personally identifiable information such as an email address, screen name, or Apple's Advertising Identifier (IDFA). If you don't have a static identifier, you can use the code snippet below for generating a unique hyprUserId using NSUUID.

 

NSString *userIdStorageKey = @"hyprMediateUserId";
NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:userIdStorageKey];
if (!userId) {
    userId = [[NSUUID UUID] UUIDString];
    [[NSUserDefaults standardUserDefaults] setObject:userId forKey:userIdStorageKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
// initialize HYPRMediate with `userId` 


You will need to implement HyprMediateDelegate.  

@interface YourHyprMediateDelegateImplementation : NSObject <HyprMediateDelegate>

Set your delegate to get callbacks from HyprMediate: 

YourHyprMediateDelegateImplementation *delegate = [[YourHyprMediateDelegateImplementation alloc] init];
[HYPRMediate setDelegate: delegate];

Important: The HyprMediate SDK keeps a strong reference to the HyprMediateDelegate you set. If you implement the HyprMediateDelegate interface with a UIViewController, be sure to set the delegate to nil in the parent UIViewController that is dismissing the delegate, before dismissViewController: is called.

 

Check For Ads, Show Ads

After initializing, HyprMediate will be ready to check if ads are available. This is done before attempting to show an ad.  

// Check if ads are available. HyprMediate will call back your delegate's hyprMediateCanShowAd method when it has an answer for you.
[HYPRMediate checkInventory];

Once you know an ad is available and the user taps on the UI element, you can show the ad.

// Place this method in the event handler used for presenting ads. HyprMediate will call back the delegate methods implemented below.
[HYPRMediate showAd];

Both checkInventory and showAd will call back your HyprMediateDelegate. Implement the following methods on your delegate.

- (void)hyprMediateCanShowAd:(BOOL)adCanBeDisplayed {
    if (adCanBeDisplayed) {
		NSLog(@"HYPRMediate can show an ad.");
    } else {
		NSLog(@"HYPRMediate does not have an ad to show.");
    }
}
- (void)hyprMediateAdStarted {
	// HyprMediate started displaying an ad.
	// This is the appropriate time to pause any background music or game animations.
}

- (void)hyprMediateAdFinished {
	// HyprMediate finished displaying an ad.
	// This is the appropriate time to resume music and animations.
}
 
- (void)hyprMediateRewardDelivered:(HYPRMediateReward *)reward {
	// The user earned a reward. You may deliver it here.
	// If you are using server to server callbacks, this may be a useful time to check in with your servers.
	NSLog(@"User earned %qi %@", reward.virtualCurrencyAmount, reward.virtualCurrencyName);
}

- (void)hyprMediateErrorOccurred:(HYPRMediateError *)error {
	// Something went wrong with the ad display. Look at the error object for more information.
	// See the HYPRMediateErrorType for more information about types of errors.
    NSLog(@"%@", [error description]);
}

NOTE: Using alert views inside of callbacks may cause UI issues with some ad providers. For this reason, we recommend you don't use UIAlertViews in HyprMediate callbacks.

 

Initialization Callbacks (Optional)

If you would like to receive a callback after HyprMediate completes initialization, implement the following method.

- (void)hyprMediateInitializationComplete {
    // HyprMediate has finished initializing
 	// It is now safe to check for ad inventory	
}

Passing User Consent Status to HyprMarketplace (Optional)

HyprMediate currently supports passing the user's consent status to the HyprMarketplace SDK only. Please review the relevant 3rd-party ad providers' guidelines for how to pass consent status to their SDKs.

If you wish to set the user's consent status, use the following API after you initialize the SDK. 

// HyprConsentStatus can be one of CONSENT_STATUS_UNKNOWN, CONSENT_GIVEN, or CONSENT_DECLINED. If you don't have consent status for the user, you can set this to CONSENT_STATUS_UNKNOWN, which is also the default.
[HyprMX setConsentStatus:<HyprConsentStatus>];

That's it! You're up and running with HyprMediate. To add more ad providers, click here.

  • No labels