Error 403 while getFollowers : Twitter iPhone MGTwitterEngine

I was trying to access the followers list from my twitter account by using MGTwitterEngine. But it is giving error. Here is all step what i have done to fixed it.

1. In MGTwitterEngine.m change #define TWITTER_DOMAIN @”twitter.com” To #define TWITTER_DOMAIN @”api.twitter.com/1″

and  #define USE_LIBXML 0 to #define USE_LIBXML 1 (Most of the people are not doing this and getting no response)

2. In your working class.h add #import “MGTwitterEngine.h” and add its delegate <MGTwitterEngineDelegate>

3. In your working class.m add these methods:

#pragma mark TwitterEngineDelegate
– (void) requestSucceeded: (NSString *) requestIdentifier {
NSLog(@”Request %@ succeeded”, requestIdentifier);
}
– (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
NSLog(@”Request %@ failed with error: %@”, requestIdentifier, error);
}
– (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier {

}
– (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier {

NSLog(@”Recieved Object: %@”, dictionary);
}
– (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier {

NSLog(@”Direct Messages Received: %@”, messages);
}
// This method will call when you received all your followers. I have used one NSMutableArray “friendsList” to store all followers information. You can modify this according to your need.
– (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier {

NSLog(@”User Info Received: %@”, userInfo);

friendsList = [[NSMutableArray alloc]init];

for (NSDictionary *u in userInfo ) {

NSDictionary *followersDic = [[NSDictionary alloc]initWithDictionary:u];
[friendsList addObject:followersDic];
[followersDic release];
}
[self.tableView reloadData];
}

This is all what i have added in my class and then calling this method: [[GetAppDelegate() facebook] requestWithGraphPath:@”me/friends” andDelegate:self]; And it return all my followers list.

I hope this code will help to those who have scratching his head from some couple of hours 😉

!! Enjoy !!

Resize table cell according to text length

Some times we need to customize our table cell’s height according to text length. For long text we need to make a bigger cell and vice versa. Here is the method to do this:

1. define you table cell’s size and font:

#define CONST_Cell_height 50.0f
#define CONST_Cell_width 270.0f
#define CONST_textLabelFontSize     16
#define CONST_detailLabelFontSize   14

2. Here is the method to calculate table cell width:

– (int) heightOfCellWithTitle :(NSString*)titleText
andSubtitle:(NSString*)subtitleText
{
CGSize titleSize = {0, 0};
CGSize subtitleSize = {0, 0};

if (titleText && ![titleText isEqualToString:@””])
titleSize = [titleText sizeWithFont:[UIFont boldSystemFontOfSize:16]
constrainedToSize:CGSizeMake(CONST_Cell_width, 4000)
lineBreakMode:UILineBreakModeWordWrap];

if (subtitleText && ![subtitleText isEqualToString:@””])
subtitleSize = [subtitleText sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:CGSizeMake(CONST_Cell_width, 4000)
lineBreakMode:UILineBreakModeWordWrap];

descriptionLabelHeight = subtitleSize.height;

return titleSize.height + subtitleSize.height;
}

3. Use this in your table height for row:

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *title = @”Yor cell title”;
NSString *subtitle =@”Your cell subtitle”;

int height =  “some constant” + [self heightOfCellWithTitle:title andSubtitle:subtitle]; // some constant is used to adjust cell height. may be zero.

return (height < CONST_Cell_height ? CONST_Cell_height : height);

}

it will resize the table cell according to text size.

!! Enjoy !!

Masking of Image on another image

Here is a small core graphics method for masking of images:

 

– (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

CGContextRef mainViewContentContext;
CGColorSpaceRef colorSpace;

colorSpace = CGColorSpaceCreateDeviceRGB();

// create a bitmap graphics context the size of the image
mainViewContentContext = CGBitmapContextCreate (NULL, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);

// free the rgb colorspace
CGColorSpaceRelease(colorSpace);

CGImageRef maskingImage = [maskImage CGImage];
CGContextClipToMask(mainViewContentContext, CGRectMake(0, 0, maskImage.size.width, maskImage.size.height), maskingImage);
CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, image.size.width, image.size.height), self.CGImage);

// Create CGImageRef of the main view bitmap content, and then
// release that bitmap context
CGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext);

// convert the finished resized image to a UIImage
UIImage *theImage = [UIImage imageWithCGImage:mainViewContentBitmapContext];
// image is retained by the property setting above, so we can
// release the original

CGContextRelease(mainViewContentContext);
CGImageRelease(mainViewContentBitmapContext);
maskingImage = nil;
CGImageRelease(maskingImage);
// return the image
return theImage;

}

For more detail about masking please checkout Quartz 2D developer guide:

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html

 

!! Enjoy !!

Limiting Zoom level in UIPinchGestureRecognizer

Sometimes when we are zooming image by using Pinch Gesture, we can’t handle the size of zooming. Here is a small code to do this.

The code below assumes there is an instance variable CGFloat lastScale and that a view has been set for the UIPinchGestureRecognizer.

– (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {

if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
// Reset the last scale, necessary if there are multiple objects with different scales
lastScale = [gestureRecognizer scale];
}

if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
[gestureRecognizer state] == UIGestureRecognizerStateChanged) {

CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@”transform.scale”] floatValue];

// Constants to adjust the max/min values of zoom
const CGFloat kMaxScale = 2.0;
const CGFloat kMinScale = 1.0;

CGFloat newScale = 1 –  (lastScale – [gestureRecognizer scale]); // new scale is in the range (0-1)
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
CGAffineTransform transform = CGAffineTransformScale([[gestureRecognizer view] transform], newScale, newScale);
[gestureRecognizer view].transform = transform;

lastScale = [gestureRecognizer scale];  // Store the previous scale factor for the next pinch gesture call
}
}

!! Enjoy !!

iPad2

Just under one year ago, Apple shocked the computing world with a 9.7-inch touchscreen tablet that few truly expected.

Some called the original Apple iPad a large-format iPhone. Others berated the name and made jokes that were not remotely funny.

The early reviews were marginal at best – we handed the device a solid four stars. Technical folks decried the lack of Adobe Flash and the missing cameras.

Now, 60,000 apps later (according to Apple, who counts every conceivable option) and just a few weeks after the first real Android 3.0 tablet contender hit the streets (Motorola Xoom), the iPad 2 has sauntered onto the playing field.

At 241mm tall, 186mm wide, and 8.6mm thick, the iPad 2 is just a hair smaller than the original iPad and it’s thinner than the iPhone 4. It has a curved edge that makes it look a bit more ‘space age’ and, surprisingly, easier to grasp because you can curve your fingers more easily around the bezel.
With rounded edges, iPad 2 has a more contoured look, shunning the straight edges of the original iPad.  According to Kevin Keller of IHS iSuppli, the slim appearance of iPad 2 not only makes the first iPad seem bulky, but also makes other tablet devices seem gargantuan compared to iPad 2.Despite having a slimmer battery, iPad 2 is roughly 15 percent more efficient in terms of power usage compared with the original.  Foregoing the two thick cells of the first iPad, Apple used three thinner, slimmer, cells, reducing the battery’s thickness.

For the screen, Apple did away with the metal sheet structure in favor of a touchscreen with an improved glass layer.  The glass on iPad 2 is thinner, more flexible and durable, than the screen of the original iPad according to IHS tests.

Compounding all of this is the cost advantage Apple has over its competitors.  UBM indicates that Apple reportedly only spent $270 to manufacture the 32GB iPad 2, cheaper compared to the estimated cost for the Motorola Xoom.

iPad 2 is smaller, faster and more feature-rich than the first generation iPad.  Moreover, with low costs, both to manufacture and to offer consumers, others can’t match, Apple and iPad should continue to dominate the tablet market.

Have you purchased iPad 2? 🙂

Customize TabBar in iPhone

When you add Tab Bar in your iPhone project, by default its background color is black and selection color is blue. But if you need to change it add these code in your project file RootViewController-

// RootViewController.h file

@interface UITabBar (ColorExtensions)

– (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;

@end

@interface UITabBarItem (Private)

@property(retain, nonatomic) UIImage *selectedImage;

– (void)_updateView;

@end

//RootViewController.m file

@implementation UITabBar (ColorExtensions)

– (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur

{

CGColorRef cgColor = [color CGColor];

CGColorRef cgShadowColor = [shadowColor CGColor];

for (UITabBarItem *item in [self items])

if ([item respondsToSelector:@selector(selectedImage)] &&

[item respondsToSelector:@selector(setSelectedImage:)] &&

[item respondsToSelector:@selector(_updateView)])

{

CGRect contextRect;

contextRect.origin.x = 0.0f;

contextRect.origin.y = 0.0f;

contextRect.size = [[item selectedImage] size];

// Retrieve source image and begin image context

UIImage *itemImage = [item image];

CGSize itemImageSize = [itemImage size];

CGPoint itemImagePosition;

itemImagePosition.x = ceilf((contextRect.size.width – itemImageSize.width) / 2);

itemImagePosition.y = ceilf((contextRect.size.height – itemImageSize.height) / 2);

UIGraphicsBeginImageContext(contextRect.size);

CGContextRef c = UIGraphicsGetCurrentContext();

// Setup shadow

CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor);

// Setup transparency layer and clip to mask

CGContextBeginTransparencyLayer(c, NULL);

CGContextScaleCTM(c, 1.0, -1.0);

CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [itemImage CGImage]);

// Fill and end the transparency layer

CGContextSetFillColorWithColor(c, cgColor);

contextRect.size.height = -contextRect.size.height;

CGContextFillRect(c, contextRect);

CGContextEndTransparencyLayer(c);

// Set selected image and end context

[item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()];

UIGraphicsEndImageContext();

// Update the view

[item _updateView];

}

}

@end

// in ViewDidLoad{

// Give the selection color and its shadow

[[[self tabBarController] tabBar] recolorItemsWithColor:[UIColor whiteColor] shadowColor:[UIColor blackColor] shadowOffset:CGSizeMake(0.0f, -1.0f) shadowBlur:3.0f];

}

It’s works great friends 🙂

!! Enjoy !!

Removing an App from iTunes Sales (App Store)

NOTE: Your app’s availability date ultimately determines if your app is live on the App Store or not. If your availability date is set to a date in the future, even if your app is Ready for Sale, it will not be live in the App Store until your availability date approaches.

Since Rights and Pricing settings are app level settings, when you choose to remove all App Store territory settings for an app, you will be removing the entire app from the App Store and not just a specific version.

Now follow these steps:

1. Login into your iTunes Connect with your developer id: https://itunesconnect.apple.com

2. Click on App Icon

3. Click on Rights And Pricing

4. At the bottom This app will be on sale in all App Stores worldwide.
Or, you can select specific stores “here”. Click on here button to open all specific app stores.

5. Click on the “Deselect All” button to uncheck all App Store territories.

6. Click on “Save Changes” button.

7. Now when you save all these and go to back to your App icon home screen. There will be one more button appear “Delete Application” after “Set Up iAd Network”.

8. Click on Delete button and read instructions.

9. Your App become disappear from app store withing 24 hours.

!! Enjoy !!

Great help for NSCalendar..

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[NSDate alloc] init]];

[components setHour:-[components hour]];
[components setMinute:-[components minute]];
[components setSecond:-[components second]];
NSDate *today = [cal dateByAddingComponents:components toDate:[[NSDate alloc] init] options:0]; //This variable should now be pointing at a date object that is the start of today (midnight);

[components setHour:-24];
[components setMinute:0];
[components setSecond:0];
NSDate *yesterday = [cal dateByAddingComponents:components toDate: today options:0];

components = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[[NSDate alloc] init]];

[components setDay:([components day] – ([components weekday] – 1))];
NSDate *thisWeek = [cal dateFromComponents:components];

[components setDay:([components day] – 7)];
NSDate *lastWeek = [cal dateFromComponents:components];

[components setDay:([components day] – ([components day] -1))];
NSDate *thisMonth = [cal dateFromComponents:components];

[components setMonth:([components month] – 1)];
NSDate *lastMonth = [cal dateFromComponents:components];

NSLog(@”today=%@”,today);
NSLog(@”yesterday=%@”,yesterday);
NSLog(@”thisWeek=%@”,thisWeek);
NSLog(@”lastWeek=%@”,lastWeek);
NSLog(@”thisMonth=%@”,thisMonth);
NSLog(@”lastMonth=%@”,lastMonth);