photoshopを開き、image -> adjustment -> brightnessで修正する。
通常
明るさ補正
明るく成りましたね。
というか、クオリティ上げて行くには、photoshopもやらないといかんのか。。
なんてことだ。
随机应变 ABCD: Always Be Coding and … : хороший
photoshopを開き、image -> adjustment -> brightnessで修正する。
通常
明るさ補正
明るく成りましたね。
というか、クオリティ上げて行くには、photoshopもやらないといかんのか。。
なんてことだ。
info.plistに追加します。
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSExceptionDomains</key> <dict> <key>http://hpscript.com/</key> <dict> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <false/> </dict> </dict> </dict>
php
$response = array(); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $teamName = $_POST['name']; $member = $_POST['old']; $response['api'] = "succeeded"; $response['member'] = $member . " years old!"; echo json_encode($response); }
xcode console
っキタキタキタ!!!!!!!!!!!!!!!!!!!!!!!!
今回、php側はjsonで返してますが、mysqlへのinsert, fetchResultもできますね。iOSの光が見えてきた。
import UIKit class ViewController: UIViewController { let URL_SAVE_BOY = "http://hpscript.com/swift/index.php" @IBOutlet weak var NameFeild: UITextField! @IBOutlet weak var oldFeild: UITextField! @IBAction func saveBtn(_ sender: Any) { let requestURL = NSURL(string: URL_SAVE_BOY) let request = NSMutableURLRequest(url: requestURL! as URL) request.httpMethod = "POST" let teamName = NameFeild.text let memberOld = oldFeild.text let postParameters = "name="+teamName!+"&old="+memberOld!; request.httpBody = postParameters.data(using: String.Encoding.utf8) let task = URLSession.shared.dataTask(with: request as URLRequest){ data, response, error in if error != nil { print("error is \(error)") return; } do { let myJSON = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary if let parseJSON = myJSON { var msg : String! msg = parseJSON["message"] as! String? print(msg) } } catch { print(error) } } task.resume() } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
@media printで指定します。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>The HTML5 Herald</title> <meta name="description" content="The HTML5 Herald"> <link rel="stylesheet" href=""> <style> #content1 { color:blue; } @media print{ #content1{ color:green; font-size:24px; } } </style> </head> <body> <input type="button" value="印刷する" onclick="window.print();" /> <div id="content1"> <p>サッカーW杯ロシア大会には、総額約120億ドル(約1兆6000億円)の選手たちが集結する。3人のトップ選手、ネイマール、メッシ、C・ロナウドの価値は、ランキング下位のチームの市場価値を上回った。</p> </div> </body> </html>
font-size, font-colorが変わりました。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>The HTML5 Herald</title> <meta name="description" content="The HTML5 Herald"> <link rel="stylesheet" href=""> </head> <body> <input type="button" value="印刷する" onclick="window.print();" /> <div id="content1"> <p>サッカーW杯ロシア大会には、総額約120億ドル(約1兆6000億円)の選手たちが集結する。3人のトップ選手、ネイマール、メッシ、C・ロナウドの価値は、ランキング下位のチームの市場価値を上回った。</p> </div> </body> </html>
印刷ボタンを押すと、、
なるほど
URL.httpMethod = “POST”, postdata.data(using: String.Encoding.utf8) とします。
URLSession.shared.dataTask(with: request as URLRequest)
viewController.swift
let URL_SAVE_BOY = "http://www.hogehoge/api/savBoy.php" @IBOutlet weak var NameFeild: UITextField! @IBOutlet weak var oldFeild: UITextField! @IBAction func saveBtn(_ sender: Any) { let requestURL = NSURL(string: URL_SAVE_BOY) let request = NSMutableURLRequest(url: requestURL! as URL) request.httpMethod = "POST" let teamName = NameFeild.text let memberOld = oldFeild.text let postParameters = "name="+teamName!+"&old="+memberOld!; request.httpBody = postParameters.data(using: String.Encoding.utf8) let task = URLSession.shared.dataTask(with: request as URLRequest){ data, response, error in if error != nil { print("error is \(error)") return; } do { let myJSON = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary if let parseJSON = myJSON { var msg : String! msg = parseJSON["message"] as! String? print(msg) } } catch { print(error) } } task.resume() }
php側をclassで書きます。mysqliでconnectしていますが、PDOで繋げたいですね。
$response = array(); if($_SERVER["REQUEST_METHOD"] == "POST"){ $teamName = $_POST["name"]; $memberCount = $_POST["old"]; require_once '../includes/DbOperation.php'; $db = new DbOperation(); if($db->saveBoy($name,$Old)){ $response['error'] = false; $response['message'] = '登録が完了しました'; } else { $response['error'] = true; $response['message'] = '承認されていません'; } echo json_encode($response) }
class DbOperation { private $conn; function __construct(){ require_once dirname(__FILE__).'/config.php'; require_once dirname(__FILE__).'/DbConnect.php'; $db = new DbConnect(); $this -> conn = $db->connect(); } public function saveBoy($name, $old) { $stmt = $this->conn->prepare("INSERT INTO boy(name, old) values(?, ?)"); $stmt -> bind_param("ss", $name, $Old); $result = $stmt -> execute(); $stmt -> close(); if($result){ return true; } else { return false; } } }
calss DbConnect { private $conn; function __construct(){ } function connect(){ require_once 'config.php'; $this -> conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); if(mysqli_connect_errno()){ echo "データベースに接続されませんでした" . mysqli_connect_errno(); return $this -> conn; } } }
define('DB_USERNAME', 'hoge'); define('DB_PASSWORD', 'hogehoge'); define('DB_HOST', 'local_host'); define('DB_NAME', 'swift');
続いて、X-codeでswiftを書いていきます。
まず、mysqlにdbをつくります。適当に、swiftとしておきます。
table名はどうしましょう。まあ、後で考えます。
続いて、phpファイルをvagrantにつくっていきます。
フォルダはapiとincludes
ok!
では、phpをつくっていきます。
import UIKit import Alamofire class Model: NSObject { private var youtubeNextPageToken: String? func loadYoutubeList(callback: (youtubeList: YoutubeList) -> (), fail:((error: NSError) ->())){ let req = request(.GET, AppConfig.youtubeURL()) req.response { (request, response, responseData, error) -> Void in do { let jsonResult = try NSJSONSerialization.JSONObjectWthData(responseData!, options: NSJSONReadingOptions.MutableContainers) as! NSMutableDictionary self.youtubeNextPageToken = jsonResult["nextPageToken"] as! String? let ary = jsonResult["items"] as! NSArray let youtubeList = YoutubeList(ary: ary) callback(youtubeList: youtubeList) } catch { print("loadYoutubeList error") } } } }
constrainをつけて行きます。
import UIKit import AVFoundation class ViewController: UIViewController { var captureSession = AVCaptureSession() var mainCamera: AVCaptureDevice? var innerCamera: AVCaptureDevice? var currentDevice: AVCaptureDevice? var photoOutput : AVCapturePhotoOutput? var cameraPreviewLayer : AVCaptureVideoPreviewLayer? override func viewDidLoad() { super.viewDidLoad() setupCaptureSession() setupDevice() setupInputOutput() setupPreviewLayer() captureSession.startRunning() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } extension ViewController { func setupCaptureSession(){ captureSession.sessionPreset = AVCaptureSession.Preset.photo } func setupDevice(){ let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: AVMediaType.video, position: AVCaptureDevice.Position.unspecified) let devices = deviceDiscoverySession.devices for device in devices { if device.position == AVCaptureDevice.Position.back { mainCamera = device } else if device.position == AVCaptureDevice.Position.front { innerCamera = device } } currentDevice = mainCamera } func setupInputOutput(){ do { let captureDeviceInput = try AVCaptureDeviceInput(device: currentDevice!) captureSession.addInput(captureDeviceInput) photoOutput = AVCapturePhotoOutput() photoOutput!.setPreparedPhotoSettingsArray([AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecType.jpeg])], completionHandler: nil) captureSession.addOutput(photoOutput!) } catch { print(error) } } func setupPreviewLayer(){ self.cameraPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession) self.cameraPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill self.cameraPreviewLayer?.connection?.videoOrientation = AVCaptureVideoOrientation.portrait self.cameraPreviewLayer?.frame = view.frame self.view.layer.insertSublayer(self.cameraPreviewLayer!, at: 0) } }