Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Amazon CognitoとAmazon S3を組み合わせてiOS向けの写真共有サービスを作...

Takaaki Tanaka
February 11, 2017

Amazon CognitoとAmazon S3を組み合わせてiOS向けの写真共有サービスを作ってみた

合同勉強会 in 福岡での発表資料です

https://connpass.com/event/49117/

Amazon CognitoとAmazon S3を組み合わせてiOS向けの写真共有サービスを作るまでの過程を話してきました。

Takaaki Tanaka

February 11, 2017
Tweet

More Decks by Takaaki Tanaka

Other Decks in Technology

Transcript

  1. • ాத ޹໌ (Takaaki Tanaka) • Ϋϥεϝιουגࣜձࣾ • iOS ΞϓϦέʔγϣϯΤϯδχΞ

    • @kongmingtrap • iOS Developer (Swift / Objective-C) • GyazSquare / GitHub
  2. Fabric SDK DMBTT"QQ%FMFHBUF6*3FTQPOEFS 6*"QQMJDBUJPO%FMFHBUF\ … func application(_ application: UIApplication, didFinishLaunchingWithOptions

    launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. Fabric.with([AWSCognito.self, Twitter.self]) return true }
  3. IAM

  4. IAM

  5. Login Button let logInButton = TWTRLogInButton { (session, error) in

    if let unwrappedSession = session { let value = unwrappedSession.authToken + ";" + unwrappedSession.authTokenSecret let provider = TwitterProvider(tokens: ["api.twitter.com": value as NSString]) let credentialsProvider = AWSCognitoCredentialsProvider( regionType:.APNortheast1, identityPoolId: "ap-northeast-1:xxxxxxxx-xxxx-xxxx- xxxx-xxxxxxxxxxxx", identityProviderManager: provider) let configuration = AWSServiceConfiguration(region:.APNortheast1, credentialsProvider: credentialsProvider) AWSServiceManager.default().defaultServiceConfiguration = configuration } else { NSLog("Login error: %@", error!.localizedDescription); } }
  6. func captureImage(sampleBuffer: CMSampleBuffer) -> UIImage { let imageBuffer: CVImageBuffer =

    CMSampleBufferGetImageBuffer(sampleBuffer)! CVPixelBufferLockBaseAddress(imageBuffer, CVPixelBufferLockFlags(rawValue: 0)) let baseAddress: UnsafeMutableRawPointer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0)! let bytesPerRow: Int = CVPixelBufferGetBytesPerRow(imageBuffer) let width:Int = CVPixelBufferGetWidth(imageBuffer) let height:Int = CVPixelBufferGetHeight(imageBuffer) let colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB() let newContext: CGContext = CGContext(data: baseAddress, width: width, height: height, bitsPerComponent: 8, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue| CGBitmapInfo.byteOrder32Little.rawValue)! let imageRef: CGImage = newContext.makeImage()! let resultImage = UIImage(cgImage: imageRef, scale: 1.0, orientation: UIImageOrientation.right) return resultImage }
  7. let request = AWSS3TransferManagerUploadRequest() request?.bucket = "report-camera" request?.key = "images/original/\

    (createAt.timeIntervalSince1970)-\(imageURL.lastPathComponent)" request?.body = imageURL return AWSS3TransferManager.default().upload(request!) S3΁ૹ৴