Monday 22 December 2014

Image zoom in /out feature in iOS [using default UIScrollView]

Step 1 : In .h file add ui-image-view object as ==>> IBOutlet UIImageView  *imgView;
 imgView object use to set image to zoom in /out

Saturday 20 December 2014

Default share option in iOS : UIActivityViewController

- (IBAction)btnSharePressed:(id)sender {
    
    //filePath must NSURL object and looking like this => file:///Users/simon/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/A5321493-318A-4A3B-8B37-E56B8B4405FC/AirDropDemo.app/ios-game-kit-sample.pdf
    
    NSString *filePath = [NSString stringWithFormat:@"file://%@",[self getFilePath:@"ios-game-kit-sample.pdf"]];
    
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[filePath] applicationActivities:nil];
                       
    [self presentViewController:activityViewController animated:YES completion:nil];
    
}

Above code share the document with all available share option, if we want to remove some option use below code.

Friday 19 December 2014

show toast type alert (Android) in iPhone (iOS)

[self.navigationItem setPrompt:@"Add photos with faces to Googlyify them!"];

Whole code for method
- (void)showToast
{
    
    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); // 1
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ // 2
       [self.navigationItem setPrompt:@"Add photos with faces to Googlyify them!"];        
    });
}

Attributed text in text view iOS

 NSArray *arrayName = @[@"Gaurav", @"Kunal", @"Madhvi",@"Ashu Sir",@"Gupta ji",@"Rajneesh",@"Vikram",@"Sakshi",@"Gaurav", @"Kunal", @"Madhvi",@"Ashu Sir",@"Gupta ji",@"Rajneesh",@"Vikram",@"Sakshi",@"Gaurav", @"Kunal", @"Madhvi",@"Ashu Sir",@"Gupta ji",@"Rajneesh",@"Vikram",@"Sakshi",@"Gaurav", @"Kunal", @"Madhvi",@"Ashu Sir",@"Gupta ji",@"Rajneesh",@"Vikram",@"Sakshi"];
    

    NSMutableString *stringName = [NSMutableString new];
    for (NSString *name in arrayName) {
        [stringName appendFormat:@"%@, ",name];
    }
 
    NSMutableAttributedString *strAtributed =[[NSMutableAttributedString alloc] initWithString:stringName];
    
    NSUInteger startName = 0, lengthName = 0;
    BOOL toogle = true;
    for (NSString *name in arrayName) {
        lengthName = name.length;
        NSRange range = NSMakeRange(startName, lengthName);
        startName += lengthName + 2;
        
        if (toogle) {
            [strAtributed addAttribute:NSForegroundColorAttributeName
                                 value:[UIColor lightGrayColor]
                                 range:range];
        } else {
            [strAtributed addAttribute:NSForegroundColorAttributeName
                                 value:[UIColor redColor]
                                 range:range];
        }
        toogle = !toogle;
    }
    
    
    [txtView setAttributedText:strAtributed];
    [txtView setFont:[UIFont systemFontOfSize:20]];

Friday 12 December 2014

SQLite3 thread safe execution in iOS


 
You can use lock (such as those enumerated in the Synchronization section of the Threading Programming Guide) or you can use a dedicated serial queue. For example, create a queue:
@property (nonatomic, strong) dispatch_queue_t databaseQueue;
Instantiate it:
self.databaseQueue = dispatch_queue_create("com.company.app.database", 0);
And whenever you want to interact with the database, you can do
dispatch_sync(self.databaseQueue, ^(void){
    // do your database activity here
});
If you want to simplify your life, the FMDB library has a FMDatabaseQueue object that does much of this for you (as well as greatly simplifying your database interaction in general).

for more detail read http://stackoverflow.com/questions/20029782/how-to-handle-multiple-thread-access-the-sqlite3-with-out-dblocked-error

Wednesday 10 December 2014

SQLite 3 query for insert into table if id not exist in some other table

INSERT INTO tbl_img_upload_queue11  (galleryID, galleryURL,imgUniqueName, imgTime, imgLat, imgLong, uploadStatus)
SELECT id, galleryURL, imgUniqueName, imgTime, imgLat, imgLong, "0" as uploadStatus FROM tbl_gallery_img as tb Where id not in (select galleryid from tbl_img_upload_queue11 where tb.id<>id) and id in(1,2,3,4)


Thursday 4 December 2014

Send push notification through php code.

If you are using distribution/ production certificate then use ssl://gateway.push.apple.com:2195

else if you are using developer account then use ssl://gateway.sandbox.push.apple.com:2195

For more detail about push notification read http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1



 $message,
                             'sound' => 'default'
                             );

        // other info which is send to push notification
        $body['others'] =   $otherMsg;

        // finally convert whole message to json and this payload variable send to apple
        $payload = json_encode($body);
        echo $payload."
";

        try {
            $ctx = stream_context_create();
            stream_context_set_option($ctx, 'ssl', 'local_cert', dirname(__FILE__).'/'.$selectPEM);
            stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
            $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

            $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) .pack('n', strlen($payload)) . $payload;
            $result = fwrite($fp, $msg, strlen($msg));
            fclose($fp);
        } catch(Exception $e) {
            continue;
        }

    }


?>


How to wait for iOS methods with completion-blocks to finish



iOS completion blocks rule. A little bit of code that runs after a (normally slow) task finishes, with full access to the classes member variables, and even read-only access to the enclosing method’s local variables.
However, sometimes you want these calls to be blocking.
*shock horror* you may be thinking. Why hasn’t he re-designed his app flow to take advantage of these new methods? (this was the general response that one guy got to his question “How to wait for methods with result/completion blocks to finish?“).
Well the answer to that question is that I already designed my UI to be fast and responsive, with cancellable actions – before it was cool I guess. So all my code is already run in worker threads. So now when I want to implement something like ALAssetManager image loading, I want to add it to code that is already nicely multi-threaded, and designed to support other methods of loading images (that use blocking reads, rather than the newer completion block design). I’d rather not totally mess up the flow of my logic, and since it’s already threaded, it’s perfectly fine to just block and wait for the asset manager to return.
So how do you do this?

Wednesday 3 December 2014

How to connect to your Amazon Instance FTP using fileZilla and others

You can download the FileZilla Client application from: http://filezilla-project.org/
You should follow these steps to upload files:
  1. Get your SSH Key in PPK format
  2. Start FileZilla
  3. Go to edit -> preferences
  4. Select SFTP 
  5. Click "Add keyfile
  6. Select the PPK file [If you don't have ppk file then import pem file, it will convert to ppk file]
  7. Save the settings (click OK in settings window) 
  8. In the connection toolbar, enter:
    1. Host: the Public DNS. You should set your server domain name
      (i.e.  xyz.bitnamiapp.com / ec2-xwz.compute-1.amazonaws.com)
      [eg. ec2-54-xx-xx-103.sp-southeast-1.compute.amazonaws.com]
    2. User: 'bitnami' / 'ec2-user'
    3. Password: leave it blank 
    4. Port: 22
  9. Click "Quickconnect
  10. If you get a message "The server's host key is unknown", click "ok" button 

Access or connect amazon ec2 using terminal

I’m setting up some free Amazon EC2 instances so I can run my Twitter data collectors without violating the terms of my Dreamhost hosting agreement or worrying about losing power on my office machine (happened just last week). Despite the many Google results for “getting started with ec2 on a mac”, the process is not that complicated.

Instructions

First, you need to generate an SSH key pair. The AWS Management Console makes this easy: Choose “Key Pairs” from the left menu bar under EC2. Follow the instructions, and download your *.pem somewhere you’ll remember.

Then, start your EC2 instance with that key pair and associate your elastic IP with that instance.

Once you have an EC2 instance up and running with your designated key pair, you should be able to SSH in just like you do to other servers:
$sudo chmod 0700 ec2-keypair.pem
$ssh -i ec2-keypair.pem ec2-user@ec2-elastic-ip

(Or, use ssh-add ec2-keypair.pem before ssh so you can drop the -i option)

Common problems

Problem: I get Permission denied (publickey).
Solutions:

Monday 1 December 2014

Create UIImage to a Blur UIImage iOS 8 default blur view

- (UIImage *) blurImage:(UIImage *) image
{
 /*
  What we need:
   CIContext
   CIImage
   CIImage
   
  
  We create a CIContext, a CIImage and a CIFilter.
  
  Then we pass the CIImage to the CIFilter.
  
  We grap the filtered Image from the outputImage-property of the CIFilter and render that with the context to a CGImageRef

  Finally, we create a UIImage from the CGImageRef and return it
  
  */
 
 
 //We create the context first to get that out of the way
 
 //TODO: 1. Create a CIContext with options nil (a default context)
 CIContext * context = [CIContext contextWithOptions:nil];
 
 //Now we create a CIImage that can be filtered with a CIFilter
 
 //TODO: 2. Create a CIImage from the UIImage* image (use -initWithImage)
 CIImage * ciImage = [[CIImage alloc] initWithImage:image];
 
 
 //We create our Filter now and set it up
 
 //TODO: 3. Create a blur-filter. It's name is @"CIGaussianBlur"
 CIFilter * blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
 
 
 //TODO: 4. Set the CIImage form Step 2 as the inputImage on the blur-filter
 //HINT: use - setValue:(your blur-filter) froKey:(the input-image-key)
 [blurFilter setValue:ciImage forKey:kCIInputImageKey];
 
 
 //Now we render the CIImage with our blur-filter
 
 //TODO: 5. Create a CGImageRef with the context from Step 1.
 
 //HINT: - createCGImage: fromRect:
 //HINT: use the outputImage-property of the blur-filter
 //HINT: the outputImage knows it's size, because it was created from another image (the UIImage)
 //you can get the required rect from the -extent method of your outputImage
 CGImageRef ref = [context createCGImage:blurFilter.outputImage fromRect:[blurFilter.outputImage extent]];
 
 
 
 //Finaly, we create a new UIImage from the CGImageRef
 
 //TODO: 6. create a UIImage from the CGImageRef.
 //HINT: There's a convenience-static-method in the UIImage for that: +imageWithCGImage:
 return [UIImage imageWithCGImage:ref];
}