Text encoding issue for NSDictionary in iOS - objective-c

In my iOS app , I have Flurry SDK for analytics. Now everything is working correctly except the special symbols are not showing correctly in Flurry. tags is NSMutableArray which stores the tag for my data. It can contain alphabets , special symbols , numbers etc. Here is my code
-(void)addTestDetails
{
NSArray *array = #[#":);&;#-(-#;""-~£~¥>=#+{!|!_'",#"'%%+|*",#"TestTag",#"123:;?&",#">|€~€",#":-(/$:&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
[params setObject:array forKey:#"Tags"];
[params setObject:#"test" forKey:#"Title"];
NSLog(#"params: %#",params);
}
When I debug , its showing me correct symbols without any encoding issue. Please have a look at below screenshots
But its shows as unicode as when I use NSLog below
params: {
Tags = (
":);&;#-(-#;-~\U00a3~\U00a5>=#+{!|!_'",
"'%%+|*",
TestTag,
"123:;?&",
">|\U20ac~\U20ac",
":-(/$:&"
);
Title = test;
}
I read some questions on stackoverflow regarding this issue which says its default & nothing wrong in it. If its correct , why its showing the same output in Flurry events as well when I download the data from Flurry server ? It should show me the correct symbols in there , right ? Correct me if I am wrong.
I tried using
[params setObject:[array componentsJoinedByString:#","] forKey:#"Tags"];
but still same issue.
Is there any other way I can fix this issue ?
Can anybody help me with this issue ? Thanks in advance.

Maybe it'll help
NSLog(#"%#", [NSString stringWithCString:contentString encoding:NSUTF8StringEncoding]);

Related

Passing a Facebook Places id, from placesPicker in iOS... to postParams for a feed publish

This has been driving me bananas! I'm trying to get my app to publish a message to the users facebook feed, and a checkin to a facebook Place after selecting a local place from the placesPicker in iOS.
I've pretty much got everything working in testing, meaning when I just hand type string values for all the postParams for the NSMutableDictionary, it posts perfectly. ex:
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"I am doing XYZ", #"message",
#"123456abc",#"tags",
#"123456xyz,#"place",
nil];
The above postParams work perfectly when published to feed, it displays the message, then checks in to the "place" id and says you are with the userid in "tags". The problem is that I am really getting the Place id from the Facebook SDK's placePicker. I've got the picker setup and working perfectly, but I can not figure out how to replace the hardcoded #"123456xyz" with the id from the picked Place.
this is currently what I have in there now:
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"I am doing XYZ", #"message",
#"123456abc",#"tags",
self.selectedPlace.id,#"place",
nil];
self.selectedplace.id does successfully contain the id of the Place, when i print it with debug/NSLog in console, it is holding the value accurately. but when i try to publish this after picking a place, I get "error: domain = com.facebook.sdk, code = 5"
Here is how self.selectedPlace is defined & synthesized:
#property (strong, nonatomic) NSObject<FBGraphPlace> *selectedPlace;
...
#synthesize selectedPlace = _selectedPlace;
...
[placePicker presentModallyFromViewController:self
animated:YES
handler:^(FBViewController *sender, BOOL donePressed) {
if (donePressed) {
self.selectedPlace = placePicker.selection;
}
}];
So, to sum my question: How can I successfully get this Place id that is stored in self.selectedPlace.id into the postParams dictionary, so that it can be successfully interpreted & published to the user's feed?
Also, I should warn everyone upfront... I am self taught and still learning, and although I can look at the code, understand what it does, and write it... I'm afraid I'm not great with the terminology & discussing/understanding some of the language... lol so it would help me a great deal if you keep that in mind in any answers or comments :) Thanks, and I'm looking forward to breaking out of my stackoverflow newb shell and becoming more apart of the community here.
Figured it out... rather than setting the post params collectively with initWithObjectsAndKeys, like this:
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"I am doing XYZ", #"message",
#"123456abc",#"tags",
self.selectedPlace.id,#"place",
nil];
Just create separate dictionaries for each param you are passing and set each one to the final postParams with setValue: forKey:
[fbPostParams setValue:self.selectedPlace.id forKey:#"place"];

Issues displaying an emoji icon in iOS app

I am having trouble figuring out how to get the emoji icons to display in the iPhone app I am working on. The issue is that then when someone posts something to the db from the app it gets displayed in the app as a square. What the app is getting from the server where the emojicon should be is something like this \uf604
Do anyone have any idea what I am doing wrong? I have been search for a good answer but so far I haven't found anything exactly related.
//more info
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
self.memoArray = [returnString JSONValue];
//when adding it to the label
cell.memoLabel.text = [itemData objectForKey: #"memo"];
What I have figured out is that for example '\Uf604' needs to be '\U0001F604'.
It's a bug in Json parser SBJSON. I have been using SBJson classes, in several projects, using several versions, and found some problems with complex unicodes that are used by some Emoji chars. That icons are represented with a very long unicode, I don't remember exactly the format, but it is like a double unicode. Inside SBJson I found some bugs where it parses large unicodes.
I did modify a method and it now works, but when I went to Stig's SBJson repository to inform about that, I found an open issue about unicodes: https://github.com/stig/json-framework/issues/115
Nevertheless, my solution was very different. In the version I was using, I just had to comment in the method scanUnicodeChar: all this if with its body:
/*
if (hi >= 0xd800) { // high surrogate char?
... if-body ... ...
}
*/
If your version includes that method and that 'if', try to delete it.
For other versions, perhaps the solution is as easy. Find a method named getStringToken: and inside it, inside a switch-case '\' statement, try to comment this way:
/*
if (SBStringIsSurrogateHighCharacter(hi)) {
..... body ....
} else if ....... {
.... ....
} else {
*/
CFStringAppendCharacters((CFMutableStringRef)acc, &hi, 1);
/*
}
*/
I have not tested this last one and surely something more have to be done in order to make everything work well.
Please follow following steps:
Convert Emoji characters to base64 and send to server.
On server side save base64 in database without decode.
When you want to display Emoji on Application then retrieve same base64 data from server.
Decode retrieve string and display on app.
Your Emoji character will display properly.
Note: When you want to Show on webPage then Decode data when you display data on WebPage.
Update to the latest SBJson, this issue was fixed.
https://github.com/stig/json-framework/tags

facebook post action url error

Im working on posting to facebook on an ios app. I had it working fine but somehow it has stopped working. I have the users auth at this point and all thats fine it just keeps giving me this error when i try to post to facebook "the post's action links must be valid urls"
below is my code for the post
currentAPICall = kDialogFeedUser;
SBJSON *jsonWriter = [[SBJSON new] autorelease];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"someName",#"name",#"www.validurl.com",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
// Dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
shareInfo.facebookShareText, #"name",//name is heading with link to above
#"text text text", #"caption",// caption makes text grayed out
#"more wonderful text", #"description",// block text for the share
shareInfo.shareUrlShort, #"link",//actual link
shareInfo.facebookShareImage, #"picture",//url of picture to be displayed
actionLinksStr, #"actions",
nil];
//the post's action links must be valid urls
//make post to wall feed
[_facebook dialog:#"feed"
andParams:params
andDelegate:self];
the post works if i remove the actionLinksStr from the params as the error says that the link within it is not valid. This has been working for months but just stopped when i tried it today and i cant seem to get it back working again. Has anyone any idea why this error would suddenly start happening with no change to the actual sharing code? the url im passing into the action link is definately valid. any help would be much appreciated thanks
edit: just gonna flag this as a bug on facebooks dev site. see if i can get any feedback from there. still a mystery to me
Make sure you are using a valid URL. In your code example above, change www.validurl.com to a complete URL: http://www.validurl.com

AVAsset has no tracks or duration when created from an ALAsset URL

I'm pulling all of the video assets from ALAssetsLibrary (Basically everything that's being recorded from the native camera app). I am then running an enumeration on each video asset that does this to each video:
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
//Get the URL location of the video
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
//Create an AVAsset from the given URL
NSDictionary *asset_options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:asset_options];//[AVURLAsset URLAssetWithURL:url options:asset_options];
//Here is the problem
NSLog([NSString stringWithFormat:#"%i", [avAsset.tracks count]]);
NSLog([NSString stringWithFormat:#"%f", CMTimeGetSeconds(avAsset.duration)]);
}
NSLog is reporting that the AVAsset that I've gotten from my ALAsset has 0 tracks, and has a duration of 0.0 seconds. I checked the url, and it's "assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV" which seems correct. I know alAsset is actually a video, and the correct video, because I've displayed alAsset.thumbnail, and it's shown the correct thumbnail for the video.
All this leads me to believe there's something going wrong in the initialization for avAsset, but for the life of me, I can't figure out what's going wrong. Can anyone help me?
Update:
I think i've confirmed that the url being given to me by ALAssetRepresentation is faulty, which is weird because it gives me the correct thumbnail. I added this code in:
NSLog([NSString stringWithFormat:#"%i", [url checkResourceIsReachableAndReturnError:&error]]);
NSLog([NSString stringWithFormat:#"%#", error]);
It gives me this:
0
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x19df60 {}
I'm still not sure what would cause that. The only thing I'm noticing is the url, which is "assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV" is different from what I've seen as I've been searching around for this. The one i've seen elsewhere looks more like "assets-library://asset/asset.MOV?id=1000000394&ext=MOV", with a number instead of an alphanumeric, dash separated name.
If it helps, I'm using XCode 4.2 Beta, and iOS5. Please let me know if you can think of anything. Thanks.
Okay, looks like it was a bug in the iOS5 beta v1. I upgraded to the newest and it worked. Thanks to those who took a look at my question.

Error while attempting to output data onto console in xcode

I am trying to output general data (source code) from a website, but it just sits there. Can't figure out if its the interface or the code. Would someone double-check for me?
#import "Lockerz_RedemptionViewController.h"
#implementation Lockerz_RedemptionViewController
-(IBAction)start: (id) sender {
while (1) {
NSMutableData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://ptzplace.lockerz.com/"]];
NSString *output = [[NSString alloc] initWithData:mydata encoding:NSASCIIStringEncoding];
NSLog(output);
}
}
The reason your NSLog doesn't work is it should use format strings.
Replace:
NSLog(output);
With:
NSLog(#"%#",output);
For more info see http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html
Why the while(1)? Are you intentionally trying to set up an infinite loop? You should just run this once, or maybe set up a periodic timer to reload it every few seconds, but certainly don't use an infinite loop for that... also it's been a while since I did anything with Cocoa networking, but you might want to look into NSURLRequest. You also may want to try NSData's dataWithContentsOfURL:options:error: and check the error parameter to better see what might be going wrong. Hope this helps you out.