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

ShareExtensionをためす

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for tinpay tinpay
November 11, 2014

 ShareExtensionをためす

ためしてみた。

Avatar for tinpay

tinpay

November 11, 2014
Tweet

More Decks by tinpay

Other Decks in Programming

Transcript

  1. 5BSHFUΛ௥Ճ͢Δ import UIKit import Social ! class ShareViewController: SLComposeServiceViewController {

    ! override func isContentValid() -> Bool { return true } ! override func didSelectPost() { self.extensionContext!.completeRequestReturningItems([], completionHandler: nil) } ! override func configurationItems() -> [AnyObject]! { return NSArray() } ! } 4IBSF7JFX$POUSPMMFSTXJGU όϦσʔγϣϯ ౤ߘϘλϯλοϓ࣌ DPOpHVSBUJPOΞΠςϜͷઃఆ
  2. $POpHVSBUJPOΞΠςϜͷ௥Ճ override func configurationItems() -> [AnyObject]! { var configurationItem :

    SLComposeSheetConfigurationItem = SLComposeSheetConfigurationItem() //λΠτϧ configurationItem.title = "ϧʔϜ" //બ୒͞Ε͍ͯΔϧʔϜ໊ configurationItem.value = "ϚΠνϟοτ"; configurationItem.tapHandler = { [unowned self] in var storyboard : UIStoryboard = UIStoryboard(name: "SelectRoom",bundle: nil) // var vc : SelectRoomTableViewController = storyboard.instantiateInitialViewController() as SelectRoomTableViewController // self.pushConfigurationViewController(vc) } return [configurationItem] } 4IBSF7JFX$POUSPMMFSTXJGU
  3. 4IBSF͢Δ 4IBSF7JFX$POUSPMMFSTXJGU override func didSelectPost() { var inputItem : NSExtensionItem

    = self.extensionContext!.inputItems[0] as NSExtensionItem var outputItem : NSExtensionItem = inputItem.copy() as NSExtensionItem; var itemProvider : NSItemProvider = inputItem.attachments![0] as NSItemProvider if (itemProvider.hasItemConformingToTypeIdentifier("public.url")) { itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (urlItem, error) in if (error != nil) { println("Unable to add as a URL") //Τϥʔ಺༰ΛϗετΞϓϦʹ఻͑Δ self.extensionContext!.cancelRequestWithError(error) } else if let url = urlItem as? NSURL { //ೖྗ͞ΕͨςΩετΛઃఆ͢Δ outputItem.attributedContentText = NSAttributedString(string:self.contentText, attributes:nil); //࣮૷Λ͔͘ //࣮ࡍʹ౤ߘͨ͠ΞΠςϜΛϗετΞϓϦʹ఻͑Δ self.extensionContext!.completeRequestReturningItems([outputItem], completionHandler: nil) } }) } }
  4. &YUFOTJPOͰݺͼग़͠ //ೖྗ͞ΕͨςΩετΛઃఆ͢Δ outputItem.attributedContentText = NSAttributedString(string:self.contentText, attributes:nil); //࣮૷Λ͔͘ var token:String =

    UICKeyChainStore.stringForKey("accessToken", service: "chat", accessGroup: "com.chatwork.inhouse.hogehogehoge") ! //࣮ࡍʹ౤ߘͨ͠ΞΠςϜΛϗετΞϓϦʹ఻͑Δ self.extensionContext!.completeRequestReturningItems([outputItem], completionHandler: nil) 4IBSF7JFX$POUSPMMFSTXJGU