Permalink
Browse files

upgraded app. for ARC support as part of CL-59

  • Loading branch information...
1 parent 62869f7 commit b31de7039150792b0de40771fbc9253c62827b1e raju committed Jul 21, 2012
View
8 unit-test/CL-70/objective-c/PubnubTest/PubnubTest.xcodeproj/project.pbxproj
@@ -11,8 +11,8 @@
C8F6538A15B98D2C008535CE /* CEPubnub.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6537E15B98D2C008535CE /* CEPubnub.m */; };
C8F6538B15B98D2C008535CE /* Cipher.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538015B98D2C008535CE /* Cipher.m */; };
C8F6538C15B98D2C008535CE /* Common.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538215B98D2C008535CE /* Common.m */; };
- C8F6538D15B98D2C008535CE /* JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538415B98D2C008535CE /* JSON.m */; };
- C8F6538E15B98D2C008535CE /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538615B98D2C008535CE /* JSONKit.m */; };
+ C8F6538D15B98D2C008535CE /* JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538415B98D2C008535CE /* JSON.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
+ C8F6538E15B98D2C008535CE /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538615B98D2C008535CE /* JSONKit.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
C8F6538F15B98D2C008535CE /* UnitTestController.m in Sources */ = {isa = PBXBuildFile; fileRef = C8F6538815B98D2C008535CE /* UnitTestController.m */; };
C8FD6F4B15B93F9C00A299E6 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8FD6F4A15B93F9B00A299E6 /* UIKit.framework */; };
C8FD6F4D15B93F9C00A299E6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8FD6F4C15B93F9C00A299E6 /* Foundation.framework */; };
@@ -245,7 +245,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- CLANG_ENABLE_OBJC_ARC = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -270,7 +270,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- CLANG_ENABLE_OBJC_ARC = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
View
BIN ...proj/project.xcworkspace/xcuserdata/dahiwadkar.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
6 unit-test/CL-70/objective-c/PubnubTest/PubnubTest/AppDelegate.m
@@ -12,11 +12,7 @@ @implementation AppDelegate
@synthesize window = _window;
-- (void)dealloc
-{
- [_window release];
- [super dealloc];
-}
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
View
4 unit-test/CL-70/objective-c/PubnubTest/PubnubTest/PubNub/Base64.m
@@ -46,8 +46,8 @@ + (NSString*) encode:(const uint8_t*) input length:(NSInteger) length {
output[index + 3] = (i + 2) < length ? encodingTable[(value >> 0) & 0x3F] : '=';
}
- return [[[NSString alloc] initWithData:data
- encoding:NSASCIIStringEncoding] autorelease];
+ return [[NSString alloc] initWithData:data
+ encoding:NSASCIIStringEncoding] ;
}
View
2 unit-test/CL-70/objective-c/PubnubTest/PubnubTest/PubNub/CEPubnub.h
@@ -40,7 +40,7 @@
// Messages must be JSON compatible
@interface CEPubnub : NSObject {
@private
- id<CEPubnubDelegate> _delegate;
+ __unsafe_unretained id<CEPubnubDelegate> _delegate;
NSString* _publishKey;
NSString* _subscribeKey;
NSString* _secretKey;
View
56 unit-test/CL-70/objective-c/PubnubTest/PubnubTest/PubNub/CEPubnub.m
@@ -75,17 +75,11 @@ - (id) initWithPubNub:(CEPubnub*)pubNub url:(NSURL*)url command:(Command)command
return self;
}
-- (void) dealloc {
- [_channel release];
- [_response release];
- [_data release];
-
- [super dealloc];
-}
+
- (void) connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
// DCHECK(_response == nil);
- _response = (NSHTTPURLResponse*)[response retain];
+ _response = (NSHTTPURLResponse*)[response copy];
}
- (void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
@@ -134,10 +128,10 @@ - (void) connectionDidFinishLoading:(NSURLConnection*)connection {
- (void) connection:(NSURLConnection*)connection didFailWithError:(NSError*)error {
if ([error.domain isEqualToString:NSURLErrorDomain] && (error.code == NSURLErrorNotConnectedToInternet)) {
- NSLog(@"Network Error: Unable to connect to the Internet");
+ NSLog(@"PubNub request failed due to missing Internet connection");
switch ([self command]) {
case kCommand_SendMessage:
- [_pubNub connection:self didCompleteWithResponse:[NSArray arrayWithObjects:@"0",@"Network Error: Unable to connect to the Internet" ,@"0", nil]];
+ [_pubNub connection:self didCompleteWithResponse:[NSArray arrayWithObjects:@"0",@"PubNub request failed due to missing Internet connection" ,@"0", nil]];
break;
default:
@@ -205,14 +199,7 @@ - (void) dealloc {
for (PubNubConnection* connection in _connections) {
[connection cancel];
}
- [_connections release];
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- [_publishKey release];
- [_subscribeKey release];
- [_secretKey release];
- [_host release];
- [_subscriptions release];
- [super dealloc];
+
}
-(NSDictionary*) getEncryptedDictionary:(NSDictionary*)message
@@ -304,7 +291,6 @@ - (void) publish:(NSDictionary * )arg1{
command:kCommand_SendMessage
channel:channel];
[_connections addObject:connection];
- [connection release];
}
- (void) _resubscribeToChannel:(NSString*)channel timeToken:(NSString*)timeToken {
@@ -315,15 +301,15 @@ - (void) _resubscribeToChannel:(NSString*)channel timeToken:(NSString*)timeToken
command:kCommand_ReceiveMessage
channel:channel];
[_connections addObject:connection];
- [connection release];
+
}
- (void) _resubscribeToChannel:(NSString*)channel {
// Ensure Single Connection
if (_subscriptions && [_subscriptions count] > 0) {
BOOL channel_exist = NO;
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:channel])
{
channel_exist = YES;
@@ -332,7 +318,7 @@ - (void) _resubscribeToChannel:(NSString*)channel {
}
if (!channel_exist) {
- ChannelStatus *cs = [[[ChannelStatus alloc] init] autorelease];
+ ChannelStatus *cs = [[ChannelStatus alloc] init] ;
cs.channel = channel;
cs.connected = YES;
[_subscriptions addObject:cs];
@@ -342,10 +328,9 @@ - (void) _resubscribeToChannel:(NSString*)channel {
}
} else {
// New Channel
- ChannelStatus *cs = [[[ChannelStatus alloc] init] autorelease];
+ ChannelStatus *cs = [[ChannelStatus alloc] init] ;
cs.channel = channel;
cs.connected = YES;
- [_subscriptions release];
_subscriptions = [[NSMutableSet alloc] init];
[_subscriptions addObject:cs];
}
@@ -361,12 +346,12 @@ - (void) subscribe:(NSString*)channel {
}
- (void) unsubscribeFromChannel:(NSString*)channel {
- for (PubNubConnection* connection in [[_connections copy]autorelease]) {
+ for (PubNubConnection* connection in [_connections copy]) {
if ((connection.command == kCommand_ReceiveMessage) && (!channel || [connection.channel isEqualToString:channel])) {
NSLog(@"Did unsubscribe from PubNub channel \"%@\"", connection.channel);
[connection cancel];
[_connections removeObject:connection];
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:connection.channel])
{
it.connected=false;
@@ -393,7 +378,7 @@ - (BOOL) isSubscribedToChannel:(NSString*)channel {
return YES;
}
}
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:channel])
{
it.connected=false;
@@ -444,7 +429,6 @@ - (void) fetchHistory:(NSDictionary * )arg1 {
command:kCommand_FetchHistory
channel:channel];
[_connections addObject:connection];
- [connection release];
}
- (void) getTime {
@@ -454,7 +438,6 @@ - (void) getTime {
command:kCommand_GetTime
channel:nil];
[_connections addObject:connection];
- [connection release];
}
NSDecimalNumber* time_token = 0;
@@ -464,7 +447,7 @@ - (void) getTime1 {
NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[NSURLConnection
sendAsynchronousRequest:urlRequest
- queue:[[[NSOperationQueue alloc] init] autorelease]
+ queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response2,
NSData *data,
NSError *error)
@@ -580,7 +563,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
case kCommand_ReceiveMessage: {
NSString* timeToken = nil;
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:connection.channel])
{
if(!it.connected) {
@@ -594,7 +577,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
}
// Problem?
if (response == nil || [timeToken isEqualToString:@"0"] ) {
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:connection.channel])
{
[_subscriptions removeObject:it];
@@ -620,15 +603,15 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
if (!_subscriptions && [_subscriptions count] > 0) {
BOOL channel_exist = NO;
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:connection.channel])
{ channel_exist = YES;
break;
}
}
if (!channel_exist) {
- ChannelStatus *cs = [[[ChannelStatus alloc] init] autorelease];
+ ChannelStatus *cs = [[ChannelStatus alloc] init] ;
cs.channel = connection.channel;
cs.connected = YES;
[_subscriptions addObject:cs];
@@ -638,10 +621,9 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
}
} else {
// New Channel
- ChannelStatus *cs = [[[ChannelStatus alloc] init] autorelease];
+ ChannelStatus *cs = [[ChannelStatus alloc] init] ;
cs.channel = connection.channel;
cs.connected = true;
- [_subscriptions release];
_subscriptions = [[NSMutableSet alloc] init];
[_subscriptions addObject:cs];
}
@@ -651,7 +633,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
}
}
else {
- for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ for (ChannelStatus* it in [_subscriptions copy]) {
if ([it.channel isEqualToString:connection.channel])
{
// Connect Callback
View
23 unit-test/CL-70/objective-c/PubnubTest/PubnubTest/PubNub/Common.m
@@ -15,13 +15,13 @@
@implementation NSString (Extensions)
- (NSString*) urlEscapedString {
- return [(id)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, NULL, CFSTR(":@/?&=+"),
- kCFStringEncodingUTF8) autorelease];
+ return (__bridge id)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)self, NULL, CFSTR(":@/?&=+"),
+ kCFStringEncodingUTF8) ;
}
- (NSString*) unescapeURLString {
- return [(id)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)self, CFSTR(""),
- kCFStringEncodingUTF8) autorelease];
+ return (__bridge id)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (__bridge CFStringRef)self, CFSTR(""),
+ kCFStringEncodingUTF8) ;
}
- (BOOL) containsString:(NSString*)string {
NSRange range = [self rangeOfString:string];
@@ -58,12 +58,9 @@ + (NSString *)generateUuidString
// create a new CFStringRef (toll-free bridged to NSString)
// that you own
- NSString *uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
-
- // transfer ownership of the string
- // to the autorelease pool
- [uuidString autorelease];
+ NSString *uuidString = (__bridge NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
+
// release the UUID
CFRelease(uuid);
@@ -75,7 +72,7 @@ + (NSString *)AES128EncryptWithKey:(NSString *)key Data:(NSString *)val
Cipher *ci = [[Cipher alloc] initWithKey: key];
NSData *data =[val dataUsingEncoding: NSUTF8StringEncoding];
NSData* enc = [ci encrypt: data];
- [ci release];
+
[Base64 initialize];
return [Base64 encode:enc];
@@ -87,15 +84,15 @@ + (NSString *)AES128EncryptWithKeyAndData:(NSString *)key Data:(NSData *)val
Cipher *ci = [[Cipher alloc] initWithKey:key];
NSData *data = val ;
NSData* enc = [ci encrypt: data];
- [ci release];
+
[Base64 initialize];
return [Base64 encode: enc];
}
+ (NSString *)AES128DecryptWithKey:(NSString *)key Data:(NSString *)data
{
- Cipher *ci= [[[Cipher alloc]initWithKey:key] autorelease];
+ Cipher *ci= [[Cipher alloc]initWithKey:key] ;
[Base64 initialize];
NSData * dat= [Base64 decode:data];
@@ -105,7 +102,7 @@ + (NSString *)AES128DecryptWithKey:(NSString *)key Data:(NSString *)data
NSLog(@"Error: Failed to decrypt. Please validate symmetric (cipher) key.");
}
NSString *dec= [[NSString alloc]initWithData:decData encoding:NSUTF8StringEncoding] ;
- return [dec autorelease];
+ return dec ;
}
@end
View
6 unit-test/CL-70/objective-c/PubnubTest/PubnubTest/UnitTestController.m
@@ -42,11 +42,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-- (void)dealloc {
- [messageText release];
- [responceText release];
- [super dealloc];
-}
+
- (IBAction)continueClick:(id)sender {
[pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:@"hello_world",@"channel",[NSDictionary dictionaryWithObjectsAndKeys:@"X-code!",@"Editer",@"Objective-c",@"Language", nil],@"message", nil]];
}

0 comments on commit b31de70

Please sign in to comment.