Step 1 : In .h file add ui-image-view object as ==>> IBOutlet UIImageView *imgView;
imgView object use to set image to zoom in /out
imgView object use to set image to zoom in /out
- (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]; }
[self.navigationItem setPrompt:@"Add photos with faces to Googlyify them!"];
- (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!"]; }); }
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]];
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:
Instantiate it:
And whenever you want to interact with the database, you can do
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 |
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)
$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; } } ?>
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.$sudo chmod 0700 ec2-keypair.pem $ssh -i ec2-keypair.pem ec2-user@ec2-elastic-ip
- (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]; }
// method in every one second execute recursive "methodWhichYouWantToRecursiveCall" [self timer]; // methodWhichYouWantToRecursiveCall calls in every 1 sec - (void)timer { __weak id weakSelf = self; __block void (^timer)(void) = ^{ double delayInSeconds = 1.0; // time for recursive call dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ id strongSelf = weakSelf; if (!strongSelf) { return; } // Schedule the timer again [self timer]; // Always use strongSelf when calling a method or accessing an iVar [self methodWhichYouWantToRecursiveCall]; }); }; // Start the timer for the first time timer(); }
// Thread safe option, always keeps a single object // dispatch_once is used as critical section for multiple thread + (instancetype)sharedManager { static PhotoManager *sharedPhotoManager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedPhotoManager = [[PhotoManager alloc] init]; sharedPhotoManager->_photosArray = [NSMutableArray array]; }); return sharedPhotoManager; }
// Thread unsafe option, which is usually we used + (instancetype)sharedManager { static PhotoManager *sharedPhotoManager = nil; if (!sharedPhotoManager) { sharedPhotoManager = [[PhotoManager alloc] init]; sharedPhotoManager->_photosArray = [NSMutableArray array]; } return sharedPhotoManager; }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] setStatusBarHidden:NO]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; return YES; }
@implementation NSString (URLEncoding) - (NSString *)encodeString//:(NSStringEncoding)encoding { return (NSString *) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@";/?:@&=$+{}<>,", CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); } @end
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view layoutIfNeeded]; }
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view layoutIfNeeded]; picker.frame = datePickerTargetFrame; [self.view addSubview:picker]; }
layoutIfNeeded
forces the receiver to layout its subviews immediately if required.layoutSubviews
, and UIKit feels that your view requires layout for whatever reason (e.g. you called setNeedsLayout
when handling some user action). Then, your custom layoutSubviews
method will be called immediately instead of when it would normally be called in the regular UIKit run loop event sequence (after event handling, but before drawRect:
).layoutIfNeeded
within a single run loop:setNeedsLayout
is set so that layoutSubviews
will be called later.layoutSubviews
that changes the table view size.layoutSubviews
is done. A solution then would be for the controller to call layoutIfNeeded
in situations where it knows this might occur.#import <UIKit/UIKit.h> #import <AssetsLibrary/AssetsLibrary.h> @interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate> { ALAssetsLibrary *library; NSArray *imageArray; NSMutableArray *mutableArray; IBOutlet UICollectionView *collectionView; } -(void)allPhotosCollected:(NSArray*)imgArray; @endViewController.m
- (void)splashAnimation{ NSInteger timeForSplash = 3; UIImageView *imageViewSplash = [[UIImageView alloc] initWithFrame:mainWindow.frame]; [imageViewSplash setImage:[UIImage imageNamed:@"Default-568h"]]; [mainWindow addSubview:imageViewSplash]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timeForSplash * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [imageViewSplash removeFromSuperview]; }); }
NSString *str = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=CAADbwxRRgq8BANULcGGn3d4NPZB4LlP3tCL9YjYH3Nd0fD2XvgjG0qTECEmOsFhNhcu4NCdgYzQK3lYaATiedLRP4ZAIRgf8FBtDBYd22z5BrMabHlex12nZAbm8UfJTrPVRw5rjN8abi9"]; NSURL* url = [NSURL URLWithString:[str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSError* error = nil; NSData* data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30] returningResponse:nil error:&error]; NSString *jsonStr = [NSString stringWithUTF8String:[data bytes]]; NSMutableDictionary *dictFromServer = [NSJSONSerialization JSONObjectWithData:urlData options:kNilOptions error:&error] if (error) { NSLog(@"%@", [error localizedDescription]); } else { NSLog(@"Data has loaded successfully.%@, in dict %@",jsonStr, dictFromServer); }
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate]; UIWindow *mainWindow = [[UIApplication sharedApplication] windows].lastObject; // or UIWindow *mainWindow = [(AppDelegate*) [[UIApplication sharedApplication] delegate] window]; // If UINavigationController is on the rootViewController UINavigationController *navController = (UINavigationController*) [[appDelegate window] rootViewController]; //===================== AppDelegate.m ==================== #define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. UIStoryboard *mainStoryboard = nil; if (IS_IPHONE_5) { mainStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone5" bundle:nil]; } else { mainStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil]; } self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [mainStoryboard instantiateInitialViewController]; [self.window makeKeyAndVisible]; return YES; }
- (void)viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:1.0 // time in seconds target:self selector:@selector(timerFired) userInfo:nil repeats:YES]; } - (void)timerFired{ NSLog(@"Hello"); }
/// first import #import <QuartzCore/QuartzCore.h> //// then user this code to save images if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale); else UIGraphicsBeginImageContext(self.window.bounds.size); [self.window.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData * data = UIImagePNGRepresentation(image); [data writeToFile:@"foo.png" atomically:YES];
// Java Code StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); for (StackTraceElement item: stackTraceElements){ System.out.println(item); }