推送

//本地推送博客

http://blog.csdn.net/kepoon/article/details/22672133

//真机测试步骤

http://jingyan.baidu.com/article/22fe7ced20cc073002617f97.html





//推送知识

99元  个人 公司 可以上传APPStare
299元  企业的(测试 内部分发)  不可以上传APPStare
iTunes Connect  上线


//开发者网站developer
账号:(个人机用)上线账号:zhangqi.lanou@gmail.com
密码:Pwd4ZHANGQI
(测试机用)Account: 531348631@qq.com
Password:   w.yang@Lanou2015i

一.真机证书 - > 让电脑有使用手机进行某项操作的权力.
证书分三种:1. 真机证书 2. push证书(推送证书) 3.上线证书
二.APP ID :程序标识符
真机证书制作
1.创建证书
2.创建CSR文件(本机的钥匙串)(CSR文件包含创建证书的电脑的一些信息,我们用电脑创建的证书,只有这一台电脑可以用)
#2-1 钥匙串访问 -> 证书助理 -> 从证书颁发机构请求整数 ->存储到磁盘
 
#3.上传CSR
#4,下载cer证书文件 -> 双击安装到钥匙串
# 5,[注意] -> 这个证书只有创建CSR的那台电脑能使用,如果想在其他电脑上用,就必须让创建CSR文件的电脑将开发者证书导出为.p12的证书

#APPID :程序标识符
分:通配  和  精确两种
1.通配的 :可以用于真机测试,因为不可以选某些app servers
2.精确地 :可以选所有的app servers ,但是在xcode中的bound indentif 必须和APP ID一模一样

# 描述文件 : xcode 中中可以直接运行程序最重要的一个文件

1.描述文件选择了app id .如果你在xcode中选择了这个描述文件,你的xcode 中的bundel identifier就必须和描述的文件app id 一样

2.描述文件选择了真机测试证书,xcode 中项目选择了某个 描述文件,你的电脑中就必须安装过描述文件所选择的那个真机测试证书
3.描述文件中有一个真机列表,如果想真机测试,你的设备udid 必须在描述文件的真机列表中.

添加一台设备
1.添加设备到账号.
2,重新生成一个描述文件,让描述文件真机列表中有你的真机的UDID

 
推送机制
: 推送详解.jpg

推送流程
1.你的程序向手机系统发送一个通知的请求
2.手机系统向APNS,注册远程通知,同时返回一个device token
3.将device token 和我们的推送证书返给第三方推送服务器
4.通过第三方服务器发送消息
5.第三方服务器将要发送的消息和要接收的设备列表发送的APNS服务器
6.APNS服务器根据第三方服务器返送过来的设备列表,来一次发送消息给设备

推送证书
让某台电脑有向APNS发送消息的权力




//主要代码

//
//  AppDelegate.m
//  LocalNotification_本地推送
//
//  Created by lanou3g on 15/10/19.
//  Copyright © 2015年 fuzhongqing. All rights reserved.
//

#import "AppDelegate.h"

#warning 引入头文件
#import "APService.h"


@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    
//    //本地推送
//    
//    //=获得当前的系统版本号
//   CGFloat version = [[UIDevice currentDevice]systemVersion].floatValue;
//    
//    if(version >= 8.0) {
//        //8.0本地推送
//        
//        //创建一个本地通知对象
//     UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//        
//        //设置推送的发送时间
//        localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
//        
//        //设置时区
//        //设置默认的时区
//        localNotification.timeZone = [NSTimeZone defaultTimeZone];
//        
//        //设置重复时间
//        localNotification.repeatInterval = 1;
//        
//        //推送的文本内容
//        localNotification.alertBody = @"研发11";
//        
//        //推送的标题
//        localNotification.alertTitle = @"本地推送";
//        
//        //推送的声音
//        localNotification.soundName = UILocalNotificationDefaultSoundName;
//        
//
    //设置整个用户通知的类型配置
//        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil];
//
    //设置用户通知的表现形式
//        [application registerUserNotificationSettings:settings];
//        
//        //应用程序接收推送
//        [application scheduleLocalNotification:localNotification];
//        
//    }else{
//        
//        //8.0之前
//        
//       }
    
    
    
    
    
    
    
    
    
    //判断系统版本号
    if ([[UIDevice currentDevice]systemVersion].floatValue >= 8.0) {
        
       //8以后
        //categories:可以任意设置内容
        //设置整个用户通知的类型配置
        [APService registerForRemoteNotificationTypes:(
         UIUserNotificationTypeAlert)
         categories:nil];
        
    }else{
        
        //8之前
        //categories:只能是nil
        [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
             UIUserNotificationTypeSound |
             UIUserNotificationTypeAlert) categories:nil];
        
    }
    
    //使用极光推送必须使用这个方法
    [APService setupWithOption:launchOptions];
    
    return YES;
}

//#pragma mark----------- 接收到本地推送后执行该代理方法
//- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
//{
//    NSLog(@"line = %d,function = %s",__LINE__,__FUNCTION__);
//    
//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"发送成功" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
//    [alert show];
//
//}



#pragma mark----------执行代理方法

//接收苹果服务器返回过来的deviceToken(设置信息、标识)
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    //将deviceToken发送给推送平台(极光)
    [APService registerDeviceToken:deviceToken];
}



//该方法是接收后台数据,而且是7之前的代理方法

//接收远程通知
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"userinfo = %@",userInfo);
    //处理传过来的信息
    [APService handleRemoteNotification:userInfo];
    
}


//该方法是接收前后台的数据的方法,而且如果有该方法,上一个方法就不走了

//告诉应用程序远程通知到达,表示有数据获取。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    
    NSLog(@"userInfo = %@",userInfo);
    
    //iOS7 支持 必须的
    [APService handleRemoteNotification:userInfo];
    
}

- (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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值