有关推送
来源:互联网 发布:数据清洗入门与实践 编辑:程序博客网 时间:2024/05/20 21:21
#import "AppDelegate.h"
#import "JPUSHService.h"
#import <AdSupport/AdSupport.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//极光推送注册接口
NSString *advertisingId = [[[ASIdentifierManagersharedManager] advertisingIdentifier]UUIDString];
if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 8.0) {
//可以添加自定义categories
[JPUSHServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)categories:nil];
}else {
//categories 必须为nil
[JPUSHServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)categories:nil];
}
//如不需要使用IDFA,advertisingIdentifier可为nil
[JPUSHServicesetupWithOption:launchOptions
appKey:@"f069f7fe1c70f9c0048ce98a"
channel:@"Publish channel"
apsForProduction:NO
advertisingIdentifier:nil];
return YES;
}
//接受deviceToken
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSLog(@"注册推送成功:%@",deviceToken);
//把devicetoken发送给极光推送服务器
[JPUSHServiceregisterDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"注册推送失败:%@",error);
}
//接受到推送消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:
(NSDictionary *)userInfo {
// Required,For systems with less than or equal to iOS6
[JPUSHServicehandleRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:
(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// IOS 7 Support Required
[JPUSHServicehandleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
导入极光推送SDK中的lib文件夹,需要配置静态库文件路径 BuildSetting 查找Header sea 输入lib的路径
创建Plist文件 命名为PushConfig,添加三个键值对 APS_FOR_PRODUCTION:(string) 0 APP_KEY:(在极光中注册应用产生的AppKey) CHANNEL :Publish Channel