Write Unity3d push notification on iOS, unity3dios

Source: Internet
Author: User
Tags openssl x509

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.mmIndidFinishLaunchingWithOptionsFunction 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, changedidRegisterForRemoteNotificationsWithDeviceTokenFunction 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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.