Wednesday, July 16, 2014

How to Share an Image Tweet on Twitter in BackGround in iOS Simple method


- (void)shareTwitterImage:(UIImage *)image withMessage:(NSString *)sharedMsg
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
     {
         if(granted)
         {
             NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
             
             if ([accountsArray count] > 0)
             {
                 ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
                 
                 TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:[NSDictionary dictionaryWithObject:sharedMsg forKey:@"status"] requestMethod:TWRequestMethodPOST];
                 
                 [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];
                 [postRequest setAccount:twitterAccount];
                 
                 [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                  {
                      //show status after done
                      NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                      NSLog(@"Twiter post status : %@", output);
                  }];
             }
         }
     }];
}



Tuesday, July 15, 2014

How to Get Twitter Profile information From iPhone Settings in iOS


-(void)getTwitterSettingsInfo
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init] ;
    
    ACAccountType *twitterAccountType =  [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
    if([twitterAccounts count] > 0)
    {
        ACAccount *twitterAccount = [twitterAccounts objectAtIndex:0];
        
        NSString *twitterUserName = twitterAccount.username;
        twillterUserLabel.text = twitterUserName;
        
        if(twitterIdentifier == 10) //Getting iamge if Identfier = 10
        {
            NSError *error;
            NSString * requestString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/show.json?screen_name=%@", twitterUserName];
            NSURL *verify = [NSURL URLWithString:requestString];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:verify];
            [[PFTwitterUtils twitter] signRequest:request];
            NSURLResponse *response = nil;
            NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
            
            if ( error == nil){
                NSDictionary* result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
                NSLog(@"%@",result);
                
                NSString * requestString = [result objectForKey:@"profile_image_url_https"];
                
                NSURL *url = [NSURL URLWithString:requestString];
                NSData *imageData = [NSData dataWithContentsOfURL:url];
                [profilepicButton setBackgroundImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];
                twitterIdentifier = 0;
            }
        }
        
    }
    else
        twillterUserLabel.text = @"Undefined";
    


}

How to Get Facebook Profile information from iPhone Settings in iOS Simple way


-(void)getFacebookSettingInfo
{
    ACAccountStore *accountStore = [[ACAccountStore allocinit] ;
    ACAccountType *facebookAccountType =  [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSArray *facebookAccounts = [accountStore accountsWithAccountType:facebookAccountType];
    //  NSLog(@"facebookAccounts ==== >>> %@", facebookAccounts);
    if([facebookAccounts count] > 0)
    {
        // ACAccount *facebookAccount = [facebookAccounts objectAtIndex:0];
        NSMutableArray *faceBookAccount = [facebookAccounts objectAtIndex:0];
        NSMutableArray *facebookProperties =  [faceBookAccount valueForKey:@"properties"];
        
        //NSLog(@"===== %@",facebookProperties);
        NSString *facebookName = [facebookProperties valueForKey:@"ACPropertyFullName"];
        fbUserLabel.text = facebookName;
        
        NSString *facebookID = [facebookProperties valueForKey:@"uid"];
        
        if(fbIdentifier == 10) //Gettin Image if identifer = 10
        {
            NSString *imageUrl = [[NSString allocinitWithFormat@"http://graph.facebook.com/%@/picture?type=large", facebookID];
            NSURL *url = [NSURL URLWithString:imageUrl];
            NSData *imageData = [NSData dataWithContentsOfURL:url];
            [profilepicButton setBackgroundImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];
            fbIdentifier = 0;
        }
        
        
    }
    else
        fbUserLabel.text = @"Undefined";



}