Upload Photo

Download - PHP File to Upload photo to server upload.php - Download Global.swift - Swift Class to Upload photo NetData.swift UploadPhotoClass.swift - Two View Controller Upload1ViewController.swift Upload2ViewController.swift

Download From Source code: https://drive.google.com/open?id=0B850FIVAQVZSRmRnbFMycjY0NzA

Page 51 of 76

// Global.swift import Foundation import UIKit //generate name func generat_name() -> String{ //current date time let formatter = NSDateFormatter() formatter.timeZone = NSTimeZone(name: "Asia/Kuwait") formatter.dateFormat = "yyyyMMdd-HHmmss" let current_date_time = formatter.stringFromDate(NSDate()) //random number let targetValue = 1 + Int(arc4random_uniform(1000)) let new_name = "\(current_date_time)-\(targetValue)" return new_name } //

Upload1ViewController.swift

import UIKit import Alamofire class Upload1ViewController: UIViewController ,UIImagePickerControllerDelegate,UINavigationControllerDelegate { @IBOutlet weak var imageView: UIImageView! @IBAction func choosePhoto(sender: AnyObject) { pickPhoto(sender) }

@IBAction func uploadBtn(sender: AnyObject) { let image : NSData = UIImageJPEGRepresentation(imageView.image!, 32)! let new_name = generat_name() let parameters = [ "pic" (new_name).jpg"), "otherParm" ]

:NetData(data: image, mimeType: .ImageJpeg, filename: "\ :"Value"

let urlRequest = urlRequestWithComponents("http://test.smart-kw.com/ upload.php", parameters: parameters) Alamofire.upload(urlRequest.0, data: urlRequest.1) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in print("\(totalBytesWritten) / \(totalBytesExpectedToWrite)") } .responseJSON { response in debugPrint(response) } }

Page 52 of 76

//-----------------------------------------------//MARK: Picker photo //-----------------------------------------------func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { print("Picking image") imageView.image = image dismissViewControllerAnimated(true, completion: nil)

} func imagePickerControllerDidCancel(picker: UIImagePickerController) { print("cancel picking image") dismissViewControllerAnimated(true, completion: nil) } func pickPhoto(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(.Camera) { showPhotoMenu(sender) } else { choosePhotoFromLibrary() } } func takePhotoWithCamera() { let imagePicker = UIImagePickerController() imagePicker.sourceType = .Camera imagePicker.delegate = self //imagePicker.allowsEditing = true presentViewController(imagePicker, animated: true, completion: nil) } func choosePhotoFromLibrary() { let imagePicker = UIImagePickerController() imagePicker.sourceType = .PhotoLibrary imagePicker.delegate = self //imagePicker.allowsEditing = true presentViewController(imagePicker, animated: true, completion: nil) } func showPhotoMenu(sender: AnyObject) { let alertController = UIAlertController(title: nil, message: nil,preferredStyle: .ActionSheet) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) alertController.addAction(cancelAction) let takePhotoAction = UIAlertAction(title: "Take Photo",style: .Default, handler: { _ in self.takePhotoWithCamera()}) alertController.addAction(takePhotoAction) let chooseFromLibraryAction = UIAlertAction(title:"Choose From Library", style: .Default, handler:{ _ in self.choosePhotoFromLibrary()}) alertController.addAction(chooseFromLibraryAction) //for ipad action sheet

Page 53 of 76

if let popoverController = alertController.popoverPresentationController { popoverController.sourceView = sender as? UIView popoverController.sourceRect = sender.bounds } presentViewController(alertController, animated: true, completion: nil) } } //

Upload2ViewController.swift

import UIKit import Alamofire class Upload2ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func uploadBtn(sender: AnyObject) { uploadPhotoWithProgress() } //if you wish to upload without progress bar func uploadPhotoWithoutProgress(){ let image = UIImage(named: "ios9.jpg") let new_name = generat_name() let parameters = [ "pic" :NetData(jpegImage: image!, compressionQuanlity: 72, filename: "\(new_name).jpg"), "otherParm" :"Value" ] let urlRequest = urlRequestWithComponents("http://test.smart-kw.com/ upload.php", parameters: parameters) Alamofire.upload(urlRequest.0, data: urlRequest.1) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in print("\(totalBytesWritten) / \(totalBytesExpectedToWrite)") } .responseJSON { response in debugPrint(response) } } //if you wish to upload with progress bar func uploadPhotoWithProgress(){ //indicator let progressIndicatorView = UIProgressView(frame: CGRect(x: 0.0, y: 80.0, width: self.view.bounds.width, height: 10.0)) progressIndicatorView.tintColor = UIColor.blueColor() self.view.addSubview(progressIndicatorView) let image = UIImage(named: "ios9.jpg") let new_name = generat_name()

Page 54 of 76

let parameters = [ "pic" :NetData(jpegImage: image!, compressionQuanlity: 72, filename: "\(new_name).jpg"), "otherParm" :"Value" ] let urlRequest = urlRequestWithComponents("http://test.smart-kw.com/ upload.php", parameters: parameters) Alamofire.upload(urlRequest.0, data: urlRequest.1) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in print("\(totalBytesWritten) / \(totalBytesExpectedToWrite)") dispatch_async(dispatch_get_main_queue()) { progressIndicatorView.setProgress(Float(totalBytesWritten) / Float(totalBytesExpectedToWrite), animated: true) if totalBytesWritten == totalBytesExpectedToWrite { progressIndicatorView.removeFromSuperview() } } } .responseJSON { response in debugPrint(response) } }

}

Upload.php "1", "message" => "successfully"); } else { $array = array ("code" => "0", "message" => "Possible file upload attack!". $_FILES['pic']['name']); } echo json_encode ( $array ); ?>


Page 55 of 76

News Forms



Page 56 of 76

Download for the admin-noti application: Upload Photo Class - NetData.swift - UploadPhotoClass.swift

-

Swift Class Global.swift NEWS.swift NewsAddViewController.swift NewsEditViewController.swift NewsTableViewCell.swift NewsViewController.swift

-

PHP FILE uploadphoto.php news-add.php news_select.php news-update.php

Link : https://drive.google.com/folderview?id=0B850FIVAQVZSelJCMDJpMzNieXM&usp=sharing


Page 57 of 76

//

Global.swift

import Foundation import UIKit var actInd : UIActivityIndicatorView = UIActivityIndicatorView() func showLoadingMode (loading : UIViewController){ actInd = UIActivityIndicatorView(frame: CGRectMake(0,0, 50, 50)) as UIActivityIndicatorView actInd.center = loading.view.center actInd.hidesWhenStopped = true actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray loading.view.addSubview(actInd) actInd.startAnimating() } //generate name func generat_name() -> String{ //current date time let formatter = NSDateFormatter() formatter.timeZone = NSTimeZone(name: "Asia/Kuwait") formatter.dateFormat = "yyyyMMdd-HHmmss" let current_date_time = formatter.stringFromDate(NSDate()) //random number let targetValue = 1 + Int(arc4random_uniform(1000)) let new_name = "\(current_date_time)-\(targetValue)" return new_name } // NEWS.swift import Foundation class NEWS { var id = "" var category = "" var title = "" var descp = "" var photo = "" var datepost = "" }

Page 58 of 76

//

NewsAddViewController.swift

import UIKit import Alamofire class NewsAddViewController: UIViewController, UITextFieldDelegate, UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate {

@IBOutlet @IBOutlet @IBOutlet @IBOutlet

weak weak weak weak

var var var var

categoryTf: UITextField! titleTf: UITextField! despTv: UITextView! imgView: UIImageView!

var photo_name = ""

override func viewDidLoad() { super.viewDidLoad() //set delegate categoryTf.delegate = self titleTf.delegate = self despTv.delegate = self //add gesture let tapGesture = UITapGestureRecognizer(target: self, action: "dismissKeyboard") self.view.addGestureRecognizer(tapGesture) } @IBAction func chooseAction(sender: AnyObject) { pickPhoto(sender) }

@IBAction func saveAction(sender: AnyObject) { if(imgView.image == nil){ let alert = UIAlertController(title: "Alert!", message: "Select Image", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) }else{ showLoadingMode (self) //indicator let progressIndicatorView = UIProgressView(frame: CGRect(x: 0.0, y: 80.0, width: self.view.bounds.width, height: 10.0)) progressIndicatorView.tintColor = UIColor.blueColor() self.view.addSubview(progressIndicatorView) let image : NSData = UIImageJPEGRepresentation(imgView.image!, 32)! photo_name = "\(generat_name()).jpg" let parameters = [

Page 59 of 76

"pic"

:NetData(data: image, mimeType: .ImageJpeg, filename:

"otherParm"

:"Value"

photo_name), ] let urlRequest = urlRequestWithComponents("http://applepush.smart-kw.com/ uploadphoto.php", parameters: parameters) Alamofire.upload(urlRequest.0, data: urlRequest.1) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in print("\(totalBytesWritten) / \(totalBytesExpectedToWrite)") dispatch_async(dispatch_get_main_queue()) { progressIndicatorView.setProgress(Float(totalBytesWritten) / Float(totalBytesExpectedToWrite), animated: true) if totalBytesWritten == totalBytesExpectedToWrite { progressIndicatorView.removeFromSuperview() } } } .responseJSON { response in debugPrint(response) if let j = response.result.value { var json = JSON(j) let result = json["code"].stringValue if result == "1" { self.insertNews() }else{ let alert = UIAlertController(title: "Alert!", message: "Fail", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) } } }

}

} func insertNews(){ let category = categoryTf.text let title = titleTf.text let descp = despTv.text

Page 60 of 76

//current date time let formatter = NSDateFormatter() formatter.timeZone = NSTimeZone(name: "Asia/Kuwait") formatter.dateFormat = "yyyy-MM-dd h:mm:ss a" let current_date_time = formatter.stringFromDate(NSDate()) let parameters = [ "c" : category!, "t" : title!, "d" : descp!, "p" : photo_name, "dp":current_date_time ] let url = "http://applepush.smart-kw.com/news-add.php" Alamofire.request(.GET, url, parameters: parameters).responseJSON { response in if let j = response.result.value {

actInd.stopAnimating() //swifty json var json = JSON(j) print(json) let result = json["result"].stringValue if result == "1" { let alert = UIAlertController(title: "Alert!", message: "Success", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) }else{ let alert = UIAlertController(title: "Alert!", message: "Fail", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) } } } } //-----------------------------------------------------------------//HIDE THE KEYBOARD func textFieldDidBeginEditing(textField: UITextField) { if textField == categoryTf { animateViewMoving(true, moveValue: 200) }

Page 61 of 76

} func textFieldDidEndEditing(textField: UITextField) { if textField == categoryTf { animateViewMoving(false, moveValue: 200) } } func textViewDidBeginEditing(textView: UITextView) { if textView == despTv { animateViewMoving(true, moveValue: 100) } } func textViewDidEndEditing(textView: UITextView) { if textView == despTv { animateViewMoving(false, moveValue: 100) } } func animateViewMoving (up:Bool, moveValue :CGFloat){ let movementDuration:NSTimeInterval = 0.3 let movement:CGFloat = ( up ? -moveValue : moveValue) UIView.beginAnimations( "animateView", context: nil) UIView.setAnimationBeginsFromCurrentState(true) UIView.setAnimationDuration(movementDuration ) self.view.frame = CGRectOffset(self.view.frame, 0, movement) UIView.commitAnimations() } func dismissKeyboard(){ categoryTf.resignFirstResponder() titleTf.resignFirstResponder() despTv.resignFirstResponder() } func textFieldShouldReturn(textField: UITextField) -> Bool { self.view.endEditing(true) return true } //-----------------------------------------------------------------//Photo Picker func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { print("Picking image") imgView.image = image dismissViewControllerAnimated(true, completion: nil)

} func imagePickerControllerDidCancel(picker: UIImagePickerController) { print("cancel picking image") dismissViewControllerAnimated(true, completion: nil) } func pickPhoto(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(.Camera) { showPhotoMenu(sender) } else { choosePhotoFromLibrary()

Page 62 of 76

} } func takePhotoWithCamera() { let imagePicker = UIImagePickerController() imagePicker.sourceType = .Camera imagePicker.delegate = self //imagePicker.allowsEditing = true presentViewController(imagePicker, animated: true, completion: nil) } func choosePhotoFromLibrary() { let imagePicker = UIImagePickerController() imagePicker.sourceType = .PhotoLibrary imagePicker.delegate = self //imagePicker.allowsEditing = true presentViewController(imagePicker, animated: true, completion: nil) } func showPhotoMenu(sender: AnyObject) { let alertController = UIAlertController(title: nil, message: nil,preferredStyle: .ActionSheet) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) alertController.addAction(cancelAction) let takePhotoAction = UIAlertAction(title: "Take Photo",style: .Default, handler: { _ in self.takePhotoWithCamera()}) alertController.addAction(takePhotoAction) let chooseFromLibraryAction = UIAlertAction(title:"Choose From Library", style: .Default, handler:{ _ in self.choosePhotoFromLibrary()}) alertController.addAction(chooseFromLibraryAction) //for ipad action sheet if let popoverController = alertController.popoverPresentationController { popoverController.sourceView = sender as? UIView popoverController.sourceRect = sender.bounds } presentViewController(alertController, animated: true, completion: nil) } } uploadphoto.php "1", "message" => "successfully"); } else { $array = array ("code" => "0", "message" => "Possible file upload attack!". $_FILES['pic']['name']); } echo json_encode ( $array );

Page 63 of 76

?> news-add.php query($sql); if ($result) { //send notification if (strlen($title) > 100) { $message = mb_substr($title, 0, 100, 'utf-8'); }else if (strlen($title)<=100) { $message = $title; } require_once('./PushBots.class.php'); $pb = new PushBots(); $appID = '568fef8217795948448b4567'; $appSecret = 'feab65781321dd4862f4dea32813c412'; $pb->App($appID, $appSecret); $pb->Alert($message); $pb->Sound("ping.aiff"); $pb->Badge("+1"); $pb->Platform("0"); // Custom fields - payload data $sql = "select MAX(id) as id from tblNews"; $result = $conn->query($sql); $row = $result->fetch_assoc(); $news_id = $row['id']; $customfields= array("id" => $news_id); $pb->Payload($customfields); $pb->Push(); $response = array('result' => 1); echo json_encode($response); } else { $response = array('result' => 0); echo json_encode($response); }

Page 64 of 76

} ?> // NewsTableViewCell.swift import UIKit class NewsTableViewCell: UITableViewCell {

@IBOutlet @IBOutlet @IBOutlet @IBOutlet

weak weak weak weak

var var var var

imgView: UIImageView! categoryLabel: UILabel! dateLabel: UILabel! titleLabel: UILabel!

override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } } // NewsViewController.swift class NewsViewController: UIViewController ,UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! var refreshControl:UIRefreshControl! var newsArr = [NEWS]() override func viewDidLoad() { super.viewDidLoad() tableView.dataSource = self tableView.delegate = self

//drag to referesh self.refreshControl = UIRefreshControl() self.refreshControl.attributedTitle = NSAttributedString(string: "‫)"ﺳﺤﺐ ﻟﺘﺤﺪﻳﯾﺚ‬ self.refreshControl.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged) self.tableView.addSubview(refreshControl) //tap on status bar let tapRecon : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "navigationBarDoubleTap:") tapRecon.numberOfTapsRequired = 2 navigationController?.navigationBar.addGestureRecognizer(tapRecon)

} override func viewDidAppear(animated: Bool) { super.viewDidAppear(true) //fetch Data fetchData() }

Page 65 of 76

//double tap to status bar func navigationBarDoubleTap(recognizer : UIGestureRecognizer) { tableView.setContentOffset(CGPointMake(0, 0), animated: true) } //test refresh without parameter!!! func refresh(){ print("drag to refresh") fetchData() }

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return newsArr.count }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! NewsTableViewCell let news = newsArr[indexPath.row] cell.categoryLabel.text = news.category cell.titleLabel.text = news.title cell.dateLabel.text = news.datepost let url:NSURL = NSURL(string: "http://applepush.smart-kw.com/uploads/\ (news.photo)")! cell.imgView.kf_setImageWithURL(url, placeholderImage: nil) return cell } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.deselectRowAtIndexPath(indexPath, animated: true) performSegueWithIdentifier("edit", sender: newsArr[indexPath.row]) }

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "edit" { let controller = segue.destinationViewController as! NewsEditViewController controller.news = sender as! NEWS } }

func fetchData(){ showLoadingMode(self)

let url = "http://applepush.smart-kw.com/news_select.php" Alamofire.request(.GET, url).responseJSON { response in

Page 66 of 76

if let json = response.result.value { self.newsArr = [] actInd.stopAnimating() self.refreshControl.endRefreshing() var json = JSON(json) if json.count > 0 {

for var i = 0 ; i < json.count ; i++ { let news = NEWS() news.id = json[i]["id"].stringValue news.category = json[i]["category"].stringValue news.title = json[i]["title"].stringValue news.descp = json[i]["descp"].stringValue news.photo = json[i]["photo"].stringValue news.datepost = json[i]["datepost"].stringValue self.newsArr.append(news) } self.tableView.reloadData() }else if json.count == 0 { let alert = UIAlertController(title: "Alert!", message: "No News", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) }else{ let alert = UIAlertController(title: "Alert!", message: "Fail", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) } } }

} }

Page 67 of 76

news_select.php query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $news[] = $row; } } echo json_encode($news); ?>

// NewsEditViewController.swift import UIKit import Alamofire import Kingfisher class NewsEditViewController: UIViewController , UITextFieldDelegate, UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate { var news = NEWS() @IBOutlet @IBOutlet @IBOutlet @IBOutlet

weak weak weak weak

var var var var

categoryTf: UITextField! titleTf: UITextField! despTv: UITextView! imgView: UIImageView!

var photo_name = "" var isUpdateNewImage = "0" override func viewDidLoad() { super.viewDidLoad() //set delegate categoryTf.delegate = self titleTf.delegate = self despTv.delegate = self //add gesture let tapGesture = UITapGestureRecognizer(target: self, action: "dismissKeyboard") self.view.addGestureRecognizer(tapGesture) //set data categoryTf.text = news.category titleTf.text = news.title despTv.text = news.descp let url:NSURL = NSURL(string: "http://applepush.smart-kw.com/uploads/\ (news.photo)")! imgView.kf_setImageWithURL(url) }

Page 68 of 76

@IBAction func chooseAction(sender: AnyObject) { pickPhoto(sender) }

@IBAction func updateAction(sender: AnyObject) { if(isUpdateNewImage == "1"){ showLoadingMode (self) //indicator let progressIndicatorView = UIProgressView(frame: CGRect(x: 0.0, y: 80.0, width: self.view.bounds.width, height: 10.0)) progressIndicatorView.tintColor = UIColor.blueColor() self.view.addSubview(progressIndicatorView) let image : NSData = UIImageJPEGRepresentation(imgView.image!, 32)! photo_name = "\(generat_name()).jpg" let parameters = [ "pic"

:NetData(data: image, mimeType: .ImageJpeg, filename:

photo_name), "otherParm"

:"Value"

] let urlRequest = urlRequestWithComponents("http://applepush.smart-kw.com/ uploadphoto.php", parameters: parameters) Alamofire.upload(urlRequest.0, data: urlRequest.1) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in print("\(totalBytesWritten) / \(totalBytesExpectedToWrite)") dispatch_async(dispatch_get_main_queue()) { progressIndicatorView.setProgress(Float(totalBytesWritten) / Float(totalBytesExpectedToWrite), animated: true) if totalBytesWritten == totalBytesExpectedToWrite { progressIndicatorView.removeFromSuperview() } } } .responseJSON { response in debugPrint(response) if let j = response.result.value { var json = JSON(j) let result = json["code"].stringValue if result == "1" { self.updateNews() }else{ let alert = UIAlertController(title: "Alert!", message: "Fail", preferredStyle: .Alert)

Page 69 of 76

let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) } } }

}else{ //is no need to update updateNews() }

} func updateNews(){ let category = categoryTf.text let title = titleTf.text let descp = despTv.text print("news.photo: \(news.photo)") print("photo_name: \(photo_name)") let parameters = [ "new_photo" : isUpdateNewImage, "c" : category!, "t" : title!, "d" : descp!, "p_old" : news.photo, "p" : photo_name, "id":news.id ] let url = "http://applepush.smart-kw.com/news-update.php" Alamofire.request(.GET, url, parameters: parameters).responseJSON { response in if let j = response.result.value {

actInd.stopAnimating() //swifty json var json = JSON(j) print(json) let result = json["result"].stringValue if result == "1" { let alert = UIAlertController(title: "Alert!", message: "Success", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil)

Page 70 of 76

alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) }else{ let alert = UIAlertController(title: "Alert!", message: "Fail", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) } } } } //-----------------------------------------------------------------//HIDE THE KEYBOARD func textFieldDidBeginEditing(textField: UITextField) { if textField == categoryTf { animateViewMoving(true, moveValue: 200) }

} func textFieldDidEndEditing(textField: UITextField) { if textField == categoryTf { animateViewMoving(false, moveValue: 200) } } func textViewDidBeginEditing(textView: UITextView) { if textView == despTv { animateViewMoving(true, moveValue: 100) } } func textViewDidEndEditing(textView: UITextView) { if textView == despTv { animateViewMoving(false, moveValue: 100) } } func animateViewMoving (up:Bool, moveValue :CGFloat){ let movementDuration:NSTimeInterval = 0.3 let movement:CGFloat = ( up ? -moveValue : moveValue) UIView.beginAnimations( "animateView", context: nil) UIView.setAnimationBeginsFromCurrentState(true) UIView.setAnimationDuration(movementDuration ) self.view.frame = CGRectOffset(self.view.frame, 0, movement) UIView.commitAnimations() }

func dismissKeyboard(){

Page 71 of 76

categoryTf.resignFirstResponder() titleTf.resignFirstResponder() despTv.resignFirstResponder() } func textFieldShouldReturn(textField: UITextField) -> Bool { self.view.endEditing(true) return true } //-----------------------------------------------------------------//Photo Picker func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { print("Picking image") imgView.image = image dismissViewControllerAnimated(true, completion: nil) isUpdateNewImage = "1"

} func imagePickerControllerDidCancel(picker: UIImagePickerController) { print("cancel picking image") dismissViewControllerAnimated(true, completion: nil) } func pickPhoto(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(.Camera) { showPhotoMenu(sender) } else { choosePhotoFromLibrary() } } func takePhotoWithCamera() { let imagePicker = UIImagePickerController() imagePicker.sourceType = .Camera imagePicker.delegate = self //imagePicker.allowsEditing = true presentViewController(imagePicker, animated: true, completion: nil) } func choosePhotoFromLibrary() { let imagePicker = UIImagePickerController() imagePicker.sourceType = .PhotoLibrary imagePicker.delegate = self //imagePicker.allowsEditing = true presentViewController(imagePicker, animated: true, completion: nil) } func showPhotoMenu(sender: AnyObject) { let alertController = UIAlertController(title: nil, message: nil,preferredStyle: .ActionSheet) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) alertController.addAction(cancelAction)

Page 72 of 76

let takePhotoAction = UIAlertAction(title: "Take Photo",style: .Default, handler: { _ in self.takePhotoWithCamera()}) alertController.addAction(takePhotoAction) let chooseFromLibraryAction = UIAlertAction(title:"Choose From Library", style: .Default, handler:{ _ in self.choosePhotoFromLibrary()}) alertController.addAction(chooseFromLibraryAction) //for ipad action sheet if let popoverController = alertController.popoverPresentationController { popoverController.sourceView = sender as? UIView popoverController.sourceRect = sender.bounds } presentViewController(alertController, animated: true, completion: nil) } //-----------------------------------------------------------------//Photo Picker @IBAction func deleteAction(sender: AnyObject) { print("delete photo: \(news.photo)") let parameters = [ "id":news.id, "p": news.photo ] let url = "http://applepush.smart-kw.com/news-delete.php" Alamofire.request(.GET, url, parameters: parameters).responseJSON { response in if let j = response.result.value {

actInd.stopAnimating() //swifty json var json = JSON(j) print(json) let result = json["result"].stringValue if result == "1" { self.navigationController?.popViewControllerAnimated(true) }else{ let alert = UIAlertController(title: "Alert!", message: "Fail", preferredStyle: .Alert) let okAction = UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okAction) self.presentViewController(alert, animated: true, completion: nil) } } } }

Page 73 of 76

} //news-update.php
if($isUpdateNewPhoto == "1"){ //remove old photo $path = 'uploads/'. $photo_old; if (file_exists($path)) { unlink($path); } $sql = "Update tblNews set category='$category',title='$title',descp='$descp',photo='$photo' where id=$id"; }else{ $sql = "Update tblNews set category='$category',title='$title',descp='$descp' where id=$id"; } $result = $conn->query($sql); if ($result) { $response = array('result' => 1); echo json_encode($response); } else { $response = array('result' => 0); echo json_encode($response); } } ?>

Page 74 of 76

//news-delete.php
$sql = "Delete from tblNews where id=$id"; $result = $conn->query($sql); if ($result) { $response = array('result' => 1); echo json_encode($response); } else { $response = array('result' => 0); echo json_encode($response); } } ?>

Page 75 of 76

Swift-news part 1.pdf

UIViewController ,UIImagePickerControllerDelegate,UINavigationControllerDelegate {. @IBOutlet weak var imageView: UIImageView! @IBAction func ...

282KB Sizes 3 Downloads 148 Views

Recommend Documents

part part whole post its.pdf
4. 7. 8. 11. Page 1 of 1. part part whole post its.pdf. part part whole post its.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying part part whole post its.pdf.

PART A PART B
On the blank World Map provided, do the following: 1. create a Legend that includes a coloured symbol for each of the following: ○ health risk. ○ political instability. ○ natural disaster. 2. locate and place on the map each of the 6 risks you

PART I Accounting for Managers PART II Financial ...
Introduction to Financial Accounting-Rules Concepts and Conventions.Structure and contents of ... Financial Products & Services. Money Market & Capital ...

part i and part ii district co-operative bank part i-questions based on ...
promotion-Media relations-Community relations. ... Implementing PR Campaigns-Evaluation of Feedback. ... Social Welfare Legislations and Programmes.

Part 12
Nov 28, 2005 - There are no studies comparing various concentrations of ..... property. The severity of the hypotension is related to the infusion rate and is less common with the aqueous form of amiodarone.91. Monitor the ECG because complications m

PART ONE
Sector Recommendation: Maintain Overweight. We are maintaining our overweight position on the sector, with BUYs for UOB and OCBC. Singapore Banks.

Part 2_Guide.pdf
... quality:dampness and mould. Retrieved 10 2016, from. http://www.euro.who.int/__data/assets/pdf_file/0017/43325/E92645.pdf. Page 3 of 54. Part 2_Guide.pdf.

Part 1 - GitHub
Apr 27, 2014 - Developing scalable applications with IBM MQ Light and ... Improving the sample application by separating the web-facing component from the.

Dynamic Circuits, Part 1
Energy stored in a capacitor, W, can be found from the definition of electric power: ..... All analysis method (KVL, KCL, circuit reduction, node-voltage and mesh ...

N-400 Part 1
an American firm or corporation engaged in foreign trade or commerce; or. • A minister ... bona fide organization in the United States; or. • A public international ...

Part Two
Old habits died hard. He had already made a decision. He looked at his watch. "I have convened another meeting with the Chiefs of Staff in two hours. ..... used to drive him. Maybe it was just age. At 42 it was probably time to retire and leave this

Exercises part 1 - GitHub
This R Markdown document contains exercises to accompany the course “Data analysis and visualization using R”. This document contains the exercises ...

Principal Syllabus Part - APMS
Learning resources – Self, Home, School, Community, Technology, Class ... Education, Meaning and scope of Environmental Education, Concept of sustainable ...

IBPSGuide - English_Vocabulary_Reference_The_Hindu Part-9 ...
IBPSGuide - English_Vocabulary_Reference_The_Hindu Part-9 www.ibpsguide.com.PDF. IBPSGuide - English_Vocabulary_Reference_The_Hindu Part-9 ...

Part 1
+ Corresponding Author : E-mail id : [email protected]; Ph.No. ... Batch adsorption studies were undertaken to assess the suitability of commercially ...

Part - 1
On the job. Appear Application System. (B). Online Job Allotment Application System. (C) Online Job Application System. (D). Online Java Application Systern. 42, is a 30,000 23, 2al 32% as satail algala is a sausasara rat-i tata 3. (A) at all (B)(-3-

Part 1
ion exchange, precipitation, and membrane process. However, ... Studies on fluoride removal using adsorption process ... Residue on ignition (6000C). < 5 %.

PART I
you with skills for developing project proposals for research, tools for data ... enable you to write down a project report of good quality ..... Data analysis is a.

Principal Syllabus Part - APMS
Learning resources – Self, Home, School, Community, Technology, Class ... (i) History of Education : Pre-Vedic and Post-Vedic period, Medieval. Education ...

N-400 Part 1
This work by Jennifer Gagliardi is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Explain how you are ...

VIM: The Basic Part - GitHub
Why use vim? • Because it's the best plaintext editor available! .... copy/pasting, saving, etc... • This is where you begin when you open a vim window. • To return ...

Exodus Part I.pdf
God. (Exodus 24:9-11)25 N/A N/A. The Israelites. worship the. golden calf. (Exodus 32:1-6)26 The Israelites. worship the golden. calf. Surah Al-Araf,. 7:148; (Surah Taha,. 20:85-98)27. N/A N/A Moses takes 70. Israelites to meet. Surah Al-Araf, 7:155.

WR330 Part B
Water Resources Act 1991 (as amended by the Water Act 2003), Environment Act 1995,. The Water Resources (Abstraction and Impounding) Regulations 2006. Introduction. Please read through this application form and the ... The Data Protection Act 1998. C