IOS Promotion

From AdLocus
Jump to: navigation, search

前言

適地性優惠通知服務是依據全區定向或特定地理位置定向,提供您的使用者最適合的主動式訊息,同時具有高額的分潤收益。

啟動優惠通知服務,請將相關程式碼加在 AppDelegate 處。


開啟BACKGROUND MODE

  • 為了提高Promotion Ad的分潤,我們建議您開啟此模式
  • 步驟: 開啟專案, 選擇 [Info], 在 [Custom iOS Target Properties] 中加入 [Required background modes]
  • 續上,新增 [App downloads content from the network]
 IOS Add File 5.jpg


設定位置權限(此設定'不會'造成藍提示,相容iOS8)

  • 步驟: 開啟專案, 選擇 [Info], 在 [Custom iOS Target Properties] 中加入 [NSLocationAlwaysUsageDescription]
 IOS Add File 6.jpg

實作

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
    • 加入 /* hyxenLibProMeOffPushService - Start */ ~ /* hyxenLibProMeOffPushService - End */
  • -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif
  • -(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  • -(NSString *)AdLocusAppKey

AppDelegate.h

  • 實作 HyXenProMeOffPushlineServiceDelegate
  • 宣告 HyxenLibProMeHyXenOfflinePushService
#import <UIKit/UIKit.h>
 
#import "libAdLocus_SDK.h"
@class ViewController;
 
@interface AppDelegate : UIResponder <UIApplicationDelegate,HyXenProMeOffPushlineServiceDelegate>
{
    HyxenLibProMeHyXenOfflinePushService *hyxenLibProMeOffPushService;
}
 
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) ViewController *viewController;
@property (nonatomic, strong) HyxenLibProMeHyXenOfflinePushService *hyxenLibProMeOffPushService;
 
@end

AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
 
@synthesize hyxenLibProMeOffPushService;
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 
    /* hyxenLibProMeOffPushService - Begin */
    NSString *sysVersion = [UIDevice currentDevice].systemVersion;
    CGFloat version = [sysVersion floatValue];
    if (version >= 7.0) {
        [application setMinimumBackgroundFetchInterval:60 * 60];
    }
 
    UILocalNotification *localNotif  = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
 
    if (localNotif) {
        [HyxenLibProMeHyXenOfflinePushService didReceiveLocalNotification:localNotif];
        [[UIApplication sharedApplication] cancelLocalNotification:localNotif]; 
    }    
 
    if (!hyxenLibProMeOffPushService) 
    {
        self.hyxenLibProMeOffPushService=[[HyxenLibProMeHyXenOfflinePushService alloc]init];
        hyxenLibProMeOffPushService.delegate=self;
        [hyxenLibProMeOffPushService applicationLauching];
        [hyxenLibProMeOffPushService setEnablePushService:YES];         
    }
    /* hyxenLibProMeOffPushService - End */
 
 
    // Initial View.
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[ViewController alloc] init];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
 
    return YES;
}
 
/* hyxenLibProMeOffPushService - Begin */
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif 
{
    [HyxenLibProMeHyXenOfflinePushService didReceiveLocalNotification:notif];
    [[UIApplication sharedApplication] cancelLocalNotification:notif];
}
 
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    [HyxenLibProMeHyXenOfflinePushService performFetchWithCompletionHandler:completionHandler];
}
#endif
 
-(NSString *)AdLocusAppKey
{
    return @"71b5d613b42d91c3ce601f1238fa7fb16cc53c9a682d20e084c8692d0d44690f0a3e2b53a7cbf2b9";
}
/* hyxenLibProMeOffPushService - End */