标签:unity3d ios apple 推送 push notification
先按照这个生成一大堆证书 http://www.cnblogs.com/gpwzw/archive/2012/03/31/apple_push_notification_services_tutorial_part_1-2.html
其中输入的命令有些错误,可以参考 http://www.tuicool.com/articles/vy2MbmZ
openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem openssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12 cat PushChatCert.pem PushChatKey.pem > ck.pem
配置好证书后,在UnityAppController.mm中的 didFinishLaunchingWithOptions函数添加:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([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 provider
var hexToken : String = "%" + System.BitConverter.ToString(token).Replace(‘-‘, ‘%‘);
new WWW("http://"+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,将结果发送给服务器。 我觉得可以使用一个单例,把整个这一套东西抽象出来,回头有功夫整理一下。
如果你觉得这篇文章对你有帮助,可以顺手点个顶,不但不会喜当爹,还能让更多人能看到它...
Unity3d 在 iOS 上推送( push notification ) 编写
标签:unity3d ios apple 推送 push notification
原文地址:http://blog.csdn.net/fansongy/article/details/43954515