Friday, July 19, 2013

Change UITextField placeholder text color -- iPhone

The introduction of attributed strings in UIViews in iOS 6, it's possible to assign a color to the placeholder text like this:
UIColor *color = [UIColor blackColor];
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholderText attributes:@{NSForegroundColorAttributeName: color}];

Sunday, July 14, 2013

capitalize first letter of NSString IOS - iPhone


NSString *myString = @"i love iPhone";
NSString *newString = [myString stringByReplacingCharactersInRange:NSMakeRange(0,1withString:[[myStringsubstringToIndex:1capitalizedString]];

Result -  "I love iPhone"

Facebook/Twitter API Integration in iOS6 - iPhone

You need to add Social.framework in your project.
Add  ---  #import "Social/Social.h"

You can create 3 type of service:


SLServiceTypeTwitter;
SLServiceTypeFacebook;
SLServiceTypeSinaWeibo;


For Facebook -

SLComposeViewController *facebookController=[SLComposeViewControllercomposeViewControllerForServiceType:SLServiceTypeFacebook];


if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
        SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResultresult){
        
        [facebookController dismissViewControllerAnimated:YES completion:nil];
        
        switch(result){
        case SLComposeViewControllerResultCancelled:
        default:
        {
            NSLog(@"Result Cancelled");
            
        }
            break;
        case SLComposeViewControllerResultDone:
        {
            NSLog(@"Result Post Done");
        }
            break;
    }};
    
    [facebookController addImage:[UIImage imageNamed:@"yourImage.jpg"]];
    [facebookController setInitialText:@"Check out this cool IOS Blog"];
    [facebookController addURL:[NSURL URLWithString:@"http://vijaysinghadhikari.blogspot.in/"]];
    [facebookController setCompletionHandler:completionHandler];
    [self presentViewController: facebookController animated:YES completion:nil];
}

Wednesday, July 10, 2013

Disable Cut,Copy, Select, Select All in UITextView - IOS


 Create a subclass of UITextView that overrides the canPerformAction:withSender: method to return NO for actions that you don't want to allow:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}

Tuesday, July 9, 2013

Twitter Integration in IOS 5 using Twitter Framework +iPone



1 :- Add Twitter.framework
2 :- open ViewController.m and add the following import at the top of the file:
#import <Twitter/Twitter.h>

- (IBAction)twitterButtonClicked:(id)sender {
    {
        if ([TWTweetComposeViewController canSendTweet])
        {
            TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
            [tweetSheet setInitialText:
             @"Your tweet Message"];
            [self presentModalViewController:tweetSheet animated:YES];
        }
        else
        {
            UIAlertView *alertView = [[UIAlertView alloc]
                                      initWithTitle:@"Notification"
                                      message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
                                      delegate:self
                                      cancelButtonTitle:@"OK"                                                   
                                      otherButtonTitles:nil];
            [alertView show];
        }
    }
}

GData Integration in iphone


Step 1
The first step, is to head on over to the Google Code website for the Objective-C Client, download and extract the zip file source code. Alternatively, you can get the latest and greatest version via Subversion using:
svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/ gdata-objectivec-client-read-only
If you downloaded the zip file from the website, you’ll have version 1.7.0, and if you used the svn code you’ll have a -read-only folder.
Step 2
Open up the GData XCode Project from your downloaded folder as well as your iPhone App XCode project.
Step 3
Drag over the GData Sources Folder from the GData project to your iPhone App project and add it as reference [don't check the box for Copy items into destination group's folder (if needed).] You do not need to copy over all the files into your project. You can, but it’s not required.
Step 4
Open up the build settings for your iPhone App project. Located and set the following settings. * Header Search Paths: /usr/include/libxml2 ../gdata-objectivec-client-1.9.1/Source * Other Linker Flags: -lxml2, -ObjC
For the Debug build configuration only, add the Other C Flags setting so that the library’s debug-only code is included:
Other C Flags: -DDEBUG=1
Step 5
Now be sure that the downloaded source code is in the same directory in which your actual Code Folder is.
Step 6 Make sure I've the frameworks "SystemConfiguration.FrameWork" and "Security.FrameWork" added to your project.
.These are the steps for GData integration

Check dis Link 4 more help ;-
http://hoishing.wordpress.com/2011/08/23/gdata-objective-c-client-setup-in-xcode-4/

Monday, July 8, 2013

App executing tasks in background +iPhone


-(void) applicationDidEnterBackground:(UIApplication*)application {
    
    UIApplication *app = [UIApplication sharedApplication];
    UIBackgroundTaskIdentifier bgTask = 0;
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
    }];
}