程序信息推送

本文是依赖信鸽推送,并介绍代码部分.
申请完信鸽推送后,接入应用,并上传相应的测试和开发证书,下载SDK并拖到工程中,

//第一步
//在application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中写:
//ACCESS ID和 ACCESS KEY]分别是信鸽推送自动生成的,直接复制粘贴就好
[XGPush startApp:ACCESS ID appKey: ACCESS KEY];
//我们得判断系统版本是否大于等于8.0
if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0){
    //如果系统版本大于8.0的方法
    //设置远程通知配置
    [application registerUserNotificationSetting:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert  categories:nil]];
    //注册远程通知
    [application registerForRemoteNoticafications];
}else{
    //系统低于8.0
    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge  |  UIRemoteNotificationTypeSound  |     UIRemoteNotificationTypeAlert];

}
// 注册成功时调用

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

    NSLog(@"%@",deviceToken);
    // 在这里去向服务器发送deviceToken
    // 信鸽推送,注册设备
    [XGPush registerDevice:deviceToken];

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

    // userInfo 字典中存储了关于推送的信息
    //以及我app需要的id
    application.applicationIconBadgeNumber = 0;

}
// 注册失败时回调
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{

    NSLog(@"%@",error);

}

你可能感兴趣的:(UI基本知识)