配置证书
先按照这个生成一大堆证书
其中输入的命令有些错误,可以参考
openssl x509 -in aps_development.cer -inform der -out PushChatCert.pemopenssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12cat PushChatCert.pem PushChatKey.pem > ck.pem
配置好证书后,在UnityAppController.mm中的 didFinishLaunchingWithOptions函数添加:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {// use registerUserNotificationSettings[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];[application registerForRemoteNotifications];} else {// use registerForRemoteNotifications[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];}#else// use registerForRemoteNotifications[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];#endif
这样就完成了对注册的配置,对于Unity3d自带的注册,,应该是不兼容IOS8系统
function Start() {NotificationServices.RegisterForRemoteNotificationTypes(RemoteNotificationType.Alert |RemoteNotificationType.Badge |RemoteNotificationType.Sound);}function Update () {if (!tokenSent) {var token : byte[] = NotificationServices.deviceToken;if (token != null) {// send token to a providervar hexToken : String = "%" + System.BitConverter.ToString(token).Replace(‘-‘, ‘%’);new WWW(""+address+"/?token="+hexToken);tokenSent = true;}}}
如果使用Unity3d可以在didRegisterForRemoteNotificationsWithDeviceToken函数中加入
NSString *tokenStr = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];tokenStr = [tokenStr stringByReplacingOccurrencesOfString:@" " withString:@""];UnitySendMessage("Bridge", "onPushID",tokenStr.UTF8String);另外就是使用update来处理token也是不可行的。
获取token成功后,更改didRegisterForRemoteNotificationsWithDeviceToken函数,添加一个消息发送回unity3D,将结果发送给服务器。 我觉得可以使用一个单例,把整个这一套东西抽象出来,回头有功夫整理一下。
销售世界上第一号的产品——不是汽车,