一.首先进入极光官网 1.注册一个号 2.建一个你自己对应的项目,然后获取Appkey 填写你的Boundle id (这个就是你xcode里面plist那里)

3然后我们要上传这两个p12文件才能实现推送这个功能(下面第二步我们就去苹果开发者中心去生成)

二 生成开发证书和生产证书() 1.(https://idmsa.apple.com/IDMSWebAuth/login?appIdKey=891bd3417a7776362562d2197f89480a8547b108fd934911bcbea0110d07f757&path=%2Faccount%2F&rv=1)这是跳到开发者中心的链接,输入你公司的账号密码。登录 然后点击App IDs进入App ID列表。


添加你的id



最后在 continue 2.现在进入正题开始生成开发和生产证书了

这里的开发证书和生产证书两个选项只能选择一个(当你选择生成的是开发证书的时候就选择开发证书,反之你就选择生产证书)


这里点击钥匙那里然后就可以这里了



注意要选“login”和“My Certificates” 导出证书时要选中证书文件,不要展开private key。(这里可能第一次按右键不会出现导出证书这个选项,多点几次就会出来)


最后极光和苹果官方这两块搞定了,最后导入到xcode那里就搞定了。 导入SDK
选择1:Cocoapods导入(如何没有安装cocoapods的,看看这篇文章http://www.jianshu.com/p/a1709c1d292d) 通过Cocoapods下载地址: pod 'JPush' 如何你是swift 把下面这个粘贴到桥文件上 #import "JPUSHService.h" oc自己声明弄到appdelegate上
然后开网 info.plist 中添加如下配置以支持 http 传输。
NSAppTransportSecurity NSAllowsArbitraryLoads 把这里几个选项勾选了


最后来粘贴代码
import UIKit
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//通知类型(这里将声音、消息、提醒角标都给加上)
let userSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound],
categories: nil)
if ((UIDevice.current.systemVersion as NSString).floatValue >= 8.0) {
//可以添加自定义categories
JPUSHService.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories: nil)
}
else {
//categories 必须为nil
JPUSHService.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories: nil)
}
// 启动JPushSDK
JPUSHService.setup(withOption: nil, appKey: "7b528331738ec719195798fd",
channel: "Publish Channel", apsForProduction:true)
return true
}
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//注册 DeviceToken
JPUSHService.registerDeviceToken(deviceToken)
}
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler
completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//增加IOS 7的支持
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
//可选
NSLog("did Fail To Register For Remote Notifications With Error: \(error)")
}
//..........
} JPUSHService.setupWithOption()方法的参数说明: channel 指明应用程序包的下载渠道,为方便分渠道统计,具体值由你自行定义,如:App Store。 appKey 填写管理Portal上创建应用后自动生成的AppKey值。请确保应用内配置的 AppKey 与第1步在 Portal 上创建应用后生成的 AppKey 一致。 apsForProduction 1.3.1版本新增,用于标识当前应用所使用的APNs证书环境。 0 (默认值)表示采用的是开发证书,1 表示采用生产证书发布应用。 注:此字段的值要与Build Settings的Code Signing配置的证书环境一致。
最后我们来玩一波 (注意只能真机测试,模拟器不行)



搞定解决。
总结: 1.apple.develop中的所有证书可以删除重新制作,对已上线的应用不会有影响 2.似乎生产环境下所有的设置好不能直接在真机上测试,需要打包ipa文件提交到iTunes上同步安装到手机上测试。这相当于模拟真实用户的操作,很实用。