RocketSocket error -- No known instance method for base64EncodedData - objective-c

I'm attempting to use the RocketSocket library on a OS 10.7 but Xcode keeps complaining that the property base64Encoding not found in NSData and NSMutable regarding these lines in SRWebSocket.m:
return [[NSData dataWithBytes:md length:CC_SHA1_DIGEST_LENGTH] base64Encoding];
_secKey = keyBytes.base64Encoding;
After some googling, I found that base64Encoding is deprecated. I'm a relative noob to ObjC (and Mac in general). Anyone have any idea how to fix this problem?

Replace
_secKey = keyBytes.base64Encoding
by
_secKey = [keyBytes base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

Related

Compiling issues on STTwitter for OSX App

I've been working on an app for OSX (not my own, one that I am to maintain) that needs Twitter integrations and found the STTwitter wrapper. It says it's compatible down to OSX 10.7. However, when I try to compile it, I run into several compilation issues that I've tracked I think I've tracked down to not being able to compile with Objective-C literal subscripts.
I tries using the workaround suggested across the web for adding my own interfaces, but that didn't seem to help.
The first compilation error I get is "Array subscript is not an integer" at the following chunk of code in NSError+STTwitter.m:
NSMutableDictionary *md = [NSMutableDictionary dictionary];
md[NSLocalizedDescriptionKey] = message;
if(underlyingError) md[NSUnderlyingErrorKey] = underlyingError;
if(rateLimitLimit) md[kSTTwitterRateLimitLimit] = rateLimitLimit;
if(rateLimitRemaining) md[kSTTwitterRateLimitRemaining] = rateLimitRemaining;
if(rateLimitResetDate) md[kSTTwitterRateLimitResetDate] = rateLimitResetDate;
If I comment that code out, just to see what happens (the literal substring I believe), I get more issues in STTwitterOS.m
NSString *value = [keyValue[1] stringByReplacingOccurrencesOfString:#"\"" withString:#""];
[md setObject:value forKey:keyValue[0]];
Those give "Bad receiver type NSArray" and "Sending NSArray to parameter of incompatible type 'id
Any help would be appreciated. My objective c coding isn't that great....

Xcode 4.5.1 new warning (potentially insecure)

I upgraded my Xcode to Version 4.5.1 and suddenly previous app development had 'potentially insecure' during build.
it generally applies to declaring this type of construct:
NSString *userChoice = [NSString stringWithFormat:label1a.text]; //Warning at pulling string from label1a.text
[usrAnswer setObject:userChoice forKey:#"1"];
is this a serious warning? How do i rectify this?
You are not using a format string. Just do this:
NSString *userChoice = label1a.text;
I see a lot of people create strings with stringWithFormat:. Only use that when you are actually creating a string with format specifiers.

Objective-C, Buzztouch coding alerts - Data argument not used by format string and Semantic issue. Can someone explain what is going on?

I'm currently running Mountain Lion OS X 10.8 with Xcode 4.4 installed. I'm running the iOS 5.1 simulator. I'm using Buzztouch as a learning tool while I'm studying Objective-C and Xcode. I get the following alerts when I compile, but the build succeeds. However, I would like to know exactly what is going on and how I can remedy the situation. Thank you for any assistance you can provide. Here's the code and the alerts I'm getting:
BT_fileManager.m
Data argument not used by format string
[BT_debugger showIt:self:[NSString stringWithFormat:#"readTextFileFromBundleWithEncoding ERROR using encoding NSUTF8StringEncoding, trying NSISOLatin1StringEncoding", #""]];
Data argument not used by format string
[BT_debugger showIt:self:[NSString stringWithFormat:#"readTextFileFromCacheWithEncoding ERROR using encoding NSUTF8StringEncoding, trying NSISOLatin1StringEncoding", #""]];
BT_camera_email.m
Semantic Issue
Sending 'BT_camera_email *' to parameter of incompatible type 'id'
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSLog(#"is camera ok");
UIActionSheet *photoSourceSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image Source"
delegate:self
Again, thanks.
Greg
I have no idea what Buzztouch might be, however.... :-)
The first warning is fairly simple. In a format string there are placeholders beginning with a '%' sign to indicate where data values should be substituted. For example, to substitute a string, one would use '%#'. In the examples you show, there are no placeholders but there are data values -- empty strings. The compiler is warning that something you indicate you want to have put into the new string created by stringWithFormat: won't be.
To be sure about the second one, I'd want to see the .h file that declares BT_camera_email but my best guess is that it doesn't adopt the UIActionSheetDelegate protocol. The description of initWithTitle:... says the second parameter should be id<UIActionSheetDelegate> and that's probably what is being complained about.

NSString may not respond to EncryptAES- Xcode Warning

It seems like I have the correct code, and it compiles, runs, and builds. BUT it does not carry out certain lines of code because of the following error: "NSString may not respond to EncryptAES"
The code where the warning occurs is contained below:
- (IBAction)Encrypt {
//Change the Input String to Data
NSData *objNSData = [NSData dataWithData:[Input dataUsingEncoding: NSUTF8StringEncoding]];
//Encrypt the Data
objNSData = [Input EncryptAES:Keyword.text]; //Line with Warning
I have searched StackOverflow for problems like this and figured that to cure this error I should use some sort of code like this in my header file:
#interface  NSString
-(NSString*)AESEncrypt:????
#end
Would this fix the warning? If so, then what do I put where the questions go?
If this code will not fix the problem then what do I do to get rid of this error and make the code function?
EDIT: I have also tried this using NSData, I get the same resulting warning
You're calling EncryptAES class method against "Input" which based on your comment and code above ([Input dataUsingEncoding...) appears to be an NSString.
NSString does not offer an EncryptAES method:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
Checkout these SO posts:
AES Encryption for an NSString on the iPhone
uses: http://pastie.org/426530
iPhone - AES256 Encryption Using Built In Library
See here. Apparently EncryptAES is a "category" for NSData. I doubt that it will work on an NSString.

Adding string objects to NSMutableArray?

I have a little foundation tool test (Objective-C) that I am playing with and I have a few questions ...
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int planetLoop;
NSString *tempString;
NSMutableArray *planetArray = [[NSMutableArray alloc] init];
NSLog(#"STRING ARRAY ... Start");
for(planetLoop=0; planetLoop<10; planetLoop++) {
tempString = [NSString stringWithFormat: #"Planet_%03d", planetLoop+1];
NSLog(#"Planet_%03d", planetLoop+1);
[planetArray addObject:tempString];
}
[planetArray release];
[pool drain];
return 0;
}
First, usually I release an object after adding it to an array, but am I right in thinking that what I have currently is right because "tempString" is a string literal, and as such does not need to be allocated or released?
Secondly, when I run this (prior to execution) I get the following eror "unable to read unknown load command 0x80000022" if this a problem with my code? from searching on google it looks like it might be a bug in xCode 3.1.2, anyone have any ideas?
Finally anything I am doing wrong, the idea is to fill an array with 10 string "Planet_001" through to "Planet_010"
EDIT: Ah, I see, thats because of the "= [NSString" bit i.e.
// Autoreleased object
tempString = [NSString stringWithFormat: #"Planet_%03d", planetLoop+1];
// String literal
tempString = #"Planet_";
many thanks, much appreciated -gary-
tempString isn't actually a string literal. #"Planet_%03d" is a string literal. tempString is an autoreleased object, meaning that it will be released when the NSAutoreleasePool is drained. Basically, the memory is already managed and you don't have to do anything.
The rule is: If you new, alloc, copy or retain an object, then you have to release it. Otherwise, the memory is already managed, probably by an autorelease.
Also, you forgot to release pool. Other than that, it looks fine.
One possible reason for the "unable to read unknown load command 0x80000022" error appears to be that I've upgraded to Snow Leopard without upgrading the developers tools at the same time. It looks like the error might be caused by trying to use the 10.5 version to XCode to compile in a 10.6 environment. I will look into this tomorrow.
Xcode 3.2 is now available in the Snow Leopard (Mac OS X 10.6) release. After installing Snow Leopard, upgrade to Xcode 3.2 by installing it separately from the Xcode Tools disk image. You can install it over prior versions of Xcode, or move them aside prior to installing.
PS: When I got the "unable to read unknown load command 0x80000022" error I was running OSX 10.6.1 with xCode 3.1.2
cheers -gary-
That "load command" error is due to the fact that the executable format has changed from iPhone OS 3.0 to iPhone OS 3.1.
http://networkpx.blogspot.com/2009/09/about-lcdyldinfoonly-command.html