开发环境:OS X Yosemite 10.10.3 + Xcode 6.4
开发语言:Swift 1.2
信鸽推送SDK2.4.0Swift1.2DemoGit地址
使用方法
把
XinGeSDK2_4_0文件拷贝到工程中拷贝
XinGeAppDelegate.swift到工程中在
工程名-Bridging-Header.h桥接文件中,添加
#import "XGSetting.h" #import "XGPush.h"
AppDelegate继承XinGeAppDelegate,并且两者有且只有一个var window: UIWindow?属性。继承的方法前需要添加override关键字,例如:
import UIKit
@UIApplicationMain
class AppDelegate: XinGeAppDelegate{
var window: UIWindow?
override func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
// 在此处,可以设置UI等操作。
return super.application(application,didFinishLaunchingWithOptions: launchOptions)
}
}
从腾讯信鸽官网创建应用并提交证书。
在
XinGeAppDelegate.swift文件中填写ACCESS ID和ACCESS KEY。
添加必要的框架:
CoreGraphics.frameworkCoreTelephony.frameworkSystemConfiguration.frameworklibz.dylibCFNetwork.frameworklibsqlite3.dylib
错误及解决
Xcode输出信息:
You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:],but you still need to add "remote-notification" to the list of your supported uibackgroundmodes in your Info.plist.
解决:Target-->点击Capabilities-->打开Background Modes-->勾选Remote notification,步骤及最终结果如下图Xcode输出:
didFailToRegisterForRemoteNotifications error:未找到应用程序的“aps-environment”的授权字符串
原因:没有相应的证书
解决1(传统方法):下载相应的证书-->双击后自动安装-->Build Settings-->Code Signing-->设置Code Signing Identity和Provisioning Profile
解决2(确保在开发中心已经有对应的证书):点击屏幕左上角的Xcode-->Preferences...(快捷键:command+,)-->选择Apple IDs中你需要的ID-->点击View Details...-->点左下角的刷新按钮。如下面图片操作:-
创建通知-->测试预览,出现
Failed to load certificate,check your APNS certificate;创建通知-->确定推送,出现apns cert error!.
原因:.pem证书生成时出现错误。信鸽官方解释
情况一:生成.pem证书时,命令没有输入完全,缺少了-nodes,完成的命令为:openssl pkcs12 -in Your_APNS_DEV.p12 -out Your_APNS_DEV.pem -nodes
情况二:导出.p12证书时,选中的不是
Apple Developmetn IOS Push Services:your.app.bundleidentifier,而是展开有开发者名字的子级。 更多错误信息
参考:信鸽常见问题与解答