chenchen1986

极光推送总结

最好去极光官网下载最新的SDK,里面有demo。


先去极光注册应用,ios需要提供bundle ID,证书以及密码。安卓要提供包名。

极光推送总结 - 东辰 - 我的博客

 


iOS8之后,极光推送用了新的库,需要更新库。


(1)新建PushConfig.plist

APS_FOR_PRODUCTION 是development就是0,是production 就是1

极光推送总结 - 东辰 - 我的博客

   

(2)该加的库要全部加上

极光推送总结 - 东辰 - 我的博客

 

(3)delegate里面的代码,有四个函数要调。


#import "AppDelegate.h"


#import "APService.h"




@interface AppDelegate ()




@end




@implementation AppDelegate






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


    // Override point for customization after application launch.


    

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    self.window.backgroundColor = [UIColor whiteColor];


    [self.window makeKeyAndVisible];


    


    // Required


#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1


    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {


        //可以添加自定义categories


        [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil];

    }


    /*else {


        //categories 必须为nil


        [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];

    }

     */


#else


    //categories 必须为nil


    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |


                                                   UIRemoteNotificationTypeSound |


                                                   UIRemoteNotificationTypeAlert)];


#endif


    // Required


    [APService setupWithOption:launchOptions];


    return YES;

}



- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {


    // Required


    [APService registerDeviceToken:deviceToken];

}


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {


    // Required

    [APService handleRemoteNotification:userInfo];

}


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // IOS 7 Support Required

    [APService handleRemoteNotification:userInfo];

    completionHandler(UIBackgroundFetchResultNewData);

}



- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}



- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}



- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}




- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}




- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end



评论

热度(1)