How to show my Keyboard extension's Emojis in other device - ios

I am looking for the solution for iOS Keyboard extensions.
My problem is if I will type My Emojis using my device, so how the another device (who does not have installed my app) will be able to show that in app like Whatsapp.?

You can use Emoji Unicode
link
Example
NSString *str = #"Hi \U0001F431";
NSData *data = [str dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *valueUnicode = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *newData = [valueUnicode dataUsingEncoding:NSUTF8StringEncoding];
NSString *valueEmoj = [[NSString alloc] initWithData:newData encoding:NSNonLossyASCIIStringEncoding];
lbl.text = valueEmoj;

After doing many research I concluded that what I was expecting is currently not possible.
But this is possible that,
If I will create my own emoji keyboard, then clicking on that emoji in Keyboard extension will copy that image.
After paste that image to any textfield of apps like Whatsapp, I will be only able to share that emoji as Image.(i.e. Image sharing).
Making your own emojis like native emojis is currently not possible to be available in all public apps.
We can do this for only our apps, like Skype and Hike does.

Related

UILabel not showing emoji

I'm facing a problem about displaying emoji in a UILabel.
I get this data from a web service (i cannot change the way i get the data) :
This value is from the debugger :
__NSCFString * #"emoji \\ud83d\\ude1b\\ud83d\\ude1d" 0x000000017405ea80
Value from NSLog :
emoji \ud83d\ude1b\ud83d\ude1d
if i assign this value to my UILabel text property i get on the screen :
emoji \ud83d\ude1b\ud83d\ude1d
I tried to encode and decode the string using :
NSData *data = [string dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *dataValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return dataValue;
and when i try :
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *output = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];
i get the emoji on the screen but if a string does not have emoji inside it will be nil and get empty label on device.
I can't get it to work correctly.
Thanks for any help.
I tried your code, the second one.. and it is working perfectly:
Here is what i have:
and the output:
removing the emoji string \\ud83d\\ude1b\\ud83d\\ude1d just leave emoji.
this is using simulator, i wonder the error only appear on the device? while in simulator it's working?
Try to set your UILabel with:
//Example
[NSString stringWithUTF8String:"\ud83d"]

unable to show emoji's properly in UIlabel

I am trying to save the emojis to server and on later time receiving them.
I used the Following Code before
NSData *data = [strEmo dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *data1 = [strEmo dataUsingEncoding:NSUTF8StringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];
It generates the Hashcode for the Emoji. But decoding doesn't work. So I skipped the Idea of using this Code.
Then I used a third Party NSString+HTML.h Class. Which Sends and recieve emoji easily. But
Now the Problem is when there are so many emoji's the UIlabel on which I am showing the data, the emojis are distorted and If I saved 20 emojis it shows 12-13 only.
I have added the Pic for reference
where Yellow part is UIlabel with back colored Yellow
Buddy why are you changing the string in Data two times in a row just simply use this
NSString *uniText = [NSString stringWithUTF8String:[strEmo UTF8String]];
NSData *msgData = [uniText dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *readyString = [[NSString alloc] initWithData:msgData encoding:NSUTF8StringEncoding];
First convert your string into constant C characters then convert it into string using UTF8 encoding, now convert it into NSData as (7-bit verbose ASCII to represent all Unicode characters) using NSNonLossyASCIIStringEncoding encoding and then again string ready to send with unicode characters. Hope this should work as it is working fine in my code.

Formatted text on UITextView

I struck with a small thing i think so, in my app UITextView plays important role. So i like to add formatting feature (Bold, Italics, underline) to it.
Once i tried using,
[NotesTxtView setAllowsEditingTextAttributes:YES];
it works fine but when i save the data to db the formatted texts change to normal. What can i do for that?
Is there any solution for my problem?
Helpers are appreciated,..
You need to save style information also. NSAttributedString's method dataFromRange:documentAttributes:error: will help:
Returns an data object that contains a text stream corresponding to the characters and attributes within the given range.
So you save and restore NSData object from db.
NSDictionary *attrs = #{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType};
// export data
NSData *data =
[self.textView.attributedText
dataFromRange:NSMakeRange(0, self.textView.text.length)
documentAttributes:attrs
error:nil];
...
// save data to db, fetch later
...
// restore
self.textView.attributedText =
[[NSAttributedString alloc]
initWithData:data
options:nil
documentAttributes:&attrs
error:nil];
Consider using other document types (all available from iOS 7):
NSString *NSPlainTextDocumentType;
NSString *NSRTFTextDocumentType;
NSString *NSRTFDTextDocumentType;
NSString *NSHTMLTextDocumentType;

Change the encoding of the textfield

I am trying to type in arabic into a textfield in Titanium(creating an iOS app).
I want to change the encoding settings of the textfield to UTF-8. Need help with that.
Something like this? You can convert easily one way or the other.
NSString *foo = someTextField.text;
NSData *data = [foo dataUsingEncoding:NSUTF8StringEncoding];
NSString *fooString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
For specific appcelerator encoding types you need to refer to their documentation.
Appcelerator Encoding Spec

iOS: How to copy HTML into the cut-paste buffer?

I'm interested in letting my users copy the text they've entered into the cut-and-paste buffer, but I'd like to do that as HTML.
Is such a thing even possible? Or do I need to use a MIME format? (I have no idea.)
Thanks.
The following code will get your HTML out of your app and into Apple's Mail app. The documentation doesn't give you a great deal of help on this, so in part it's a matter of looking at what Apple's apps park on the pasteboard and then reverse engineering that. This solution draws on an earlier stackoverflow post - follow up the links there for more background.
NSLog(#"Place HTML on the pasteboard");
UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
NSString *htmlType = #"Apple Web Archive pasteboard type";
// example html string
NSString* htmlString = #"<p style=\"color:gray\"> Paragraft<br><em>Less than a word processor, more than plain text</em>";
NSMutableDictionary *resourceDictionary = [NSMutableDictionary dictionary];
[resourceDictionary setObject:[htmlString dataUsingEncoding:NSUTF8StringEncoding] forKey:#"WebResourceData"];
[resourceDictionary setObject:#"" forKey:#"WebResourceFrameName"];
[resourceDictionary setObject:#"text/html" forKey:#"WebResourceMIMEType"];
[resourceDictionary setObject:#"UTF-8" forKey:#"WebResourceTextEncodingName"];
[resourceDictionary setObject:#"about:blank" forKey:#"WebResourceURL"];
NSDictionary *containerDictionary = [NSDictionary dictionaryWithObjectsAndKeys:resourceDictionary, #"WebMainResource", nil];
NSDictionary *htmlItem = [NSDictionary dictionaryWithObjectsAndKeys:containerDictionary,htmlType,nil];
[pasteboard setItems: [NSArray arrayWithObjects: htmlItem, nil]];
// This approach draws on the blog post and comments at:
// http://mcmurrym.wordpress.com/2010/08/13/pasting-simplehtml-into-the-mail-app-ios/
This solution puts both a HTML and a plain text representation into the pasteboard:
#import <MobileCoreServices/MobileCoreServices.h>
NSString *html = #"<h1>Headline</h1>text";
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = #{#"WebMainResource": #{#"WebResourceData": data, #"WebResourceFrameName": #"", #"WebResourceMIMEType": #"text/html", #"WebResourceTextEncodingName": #"UTF-8", #"WebResourceURL": #"about:blank"}};
data = [NSPropertyListSerialization dataWithPropertyList:dict format:NSPropertyListXMLFormat_v1_0 options:0 error:nil];
NSString *archive = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *plain = [html stringByReplacingOccurrencesOfRegex:#"<[^>]+>" withString:#""];
[UIPasteboard generalPasteboard].items = #[#{#"Apple Web Archive pasteboard type": archive, (id)kUTTypeUTF8PlainText: plain}];
It uses -stringByReplacingOccurrencesOfRegex: from RegexKitLite to strip the HTML tags.
I absolutely adore this method of creating HTML-based content that you can paste into other HTML-aware apps, like Mail. However, I noticed that the above solution by Matthew Elton only allowed the pasteboard to be pasted onto HTML-aware apps. Trying to paste the exact same content into the Notes app for example, would fail.
I took the tips from this post: https://stackoverflow.com/a/1078471/351810 and can now successfully paste both HTML and plain text versions of the content that I want.
I use w3schools.
I cut and paste my html code over their example code , on any of their many "Try it yourself" tutorials and then use their "run" button.
e.g. https://www.w3schools.com/html/default.asp

Resources