Write Unity3d push notification on iOS, unity3dios
Author: Songyang
This article is from Ashura road and is prohibited for commercial purposes. For more information, see the source.
Link: http://blog.csdn.net/fansongy/article/details/43954515
Configure Certificate
First generate a bunch of certificate http://www.cnblogs.com/gpwzw/archive/2012/03/31/apple_push_notification_services_tutorial_part_1-2.html according to this
The entered command has some errors, refer to http://www.tuicool.com/articles/vy2MbmZ
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
After configuring the certificateUnityAppController.mm
IndidFinishLaunchingWithOptions
Function addition:
#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
This completes the registration configuration. For the Unity3d built-in registration, it should be incompatible with the IOS8 system.
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("http://"+address+"/?token="+hexToken);tokenSent = true;}}}
If Unity3d is used, you can add it to the didRegisterForRemoteNotificationsWithDeviceToken function.
NSString * tokenStr = [[deviceToken description] feature: [NSCharacterSet characterSetWithCharactersInString: @ "<>"]; tokenStr = [tokenStr response: @ "withString: @" "]; unitySendMessage ("Bridge", "onPushID", tokenStr. UTF8String); in addition, it is not feasible to use update to process tokens.
After the token is obtained, changedidRegisterForRemoteNotificationsWithDeviceToken
Function to send a message back to unity3D and send the result to the server. I think we can use a singleton to abstract the entire set of things and try to organize it later.
If you think this article is helpful to you, you can stick to it, not only won't like it, but also let more people see it...