Sending Emoji in Push Notifications via PHP on iOS

雨燕双飞 提交于 2019-11-29 16:01:04

问题


I'd like to send some emoji icons with push notifications, but have no idea how I do that.

Has anyone successfully implemented this with PHP? I just want to prepend my push message with a smiley face for example.

My question is purely about emoji, I have a successful APNS script.

Thanks for any guidance.


回答1:


There's a quick 'n dirty way to do this using html_entity_decode():

Example:

$lightning = html_entity_decode('',ENT_NOQUOTES,'UTF-8');
//add this to the 'alert' portion of your APNS payload:
$message = "You just got the {$lightning}SHOCKER{$lightning}!"; 

Basically, you just create an HTML Entity with the decimal (not hex) code of the Emoji icon you'd like to use, and html_entity_decode() will convert it to the correct Unicode character that you can use in a string. There's a catalog of Unicode code points at the previously-mentioned http://code.iamcal.com/php/emoji/ URL.

This method should work for any character you can't type into your text editor, emoji or not.




回答2:


This is a good resource for that: http://code.iamcal.com/php/emoji/




回答3:


Send it as additional attribute to APNS JSON payload

{"aps":{"alert":"Your Message","sound":"push1.wav"},"emoji":"emoji_name"}

but you can't display them inside of UIAlertView, you can only in application

APNS JSON PAYLOAD - more arguments

Note that JSON payload must be valid by rfc4627 so you can use only Unicode characters

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1
http://www.ietf.org/rfc/rfc4627.txt



来源:https://stackoverflow.com/questions/7012485/sending-emoji-in-push-notifications-via-php-on-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!