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

ShareExtensionをためす

tinpay
November 11, 2014

 ShareExtensionをためす

ためしてみた。

tinpay

November 11, 2014
Tweet

More Decks by tinpay

Other Decks in Programming

Transcript

  1. 4IBSF&YUFOTJPO

    Λࢼͯ͠ΈΔ
    ϞόΠϧΞϓϦ

    ษڧձ

    99෱Ҫষฏ

    View full-size slide

  2. ΞδΣϯμ
    w 4IBSF&YUFOTJPOͱ͸
    w छྨͷ4IBSF&YUFOTJPO


    4-$PNQPTF4FSWJDF7JFX$POUSPMMFSΛར༻


    6*7JFX$POUSPMMFSΛར༻

    View full-size slide

  3. 4IBSF&YUFOTJPOͱ͸

    View full-size slide

  4. ྫ͑͹

    4BGBSJ
    ԼͷਅΜதͷ

    ϘλϯΛԡ͢

    View full-size slide

  5. 5XJUUFSͷ4IBSF&YUFOTJPO

    View full-size slide

  6. &WFSOPUFͷ4IBSF&YUFOTJPO

    View full-size slide

  7. 1JOUFSFTUͷ4IBSF&YUFOTJPO

    View full-size slide

  8. 1PDLFUͷ4IBSF&YUFOTJPO

    View full-size slide

  9. छྨͷ
    4IBSF&YUFOTJPO

    View full-size slide


  10. 4-$PNQPTF4FSWJDF7JFX$POUSPMMFS
    ൚༻తͳ6*
    6*෦ͷ࣮૷͕΄΅ෆཁɻ

    ؆୯ʹ࣮૷Ͱ͖Δɻ

    View full-size slide


  11. 6*7JFX$POUSPMMFS
    ࣗ༝౓ͷߴ͍6*
    6*ɺը໘ભҠɺ͢΂ͯ

    ಠࣗͰ࣮૷͢Δඞཁ͕

    ͋Δɻ

    View full-size slide

  12. ϓϩδΣΫτ ίϯςφʔΞϓϦ
    Λͭ͘Δ

    View full-size slide

  13. 5BSHFUΛ௥Ճ͢Δ

    View full-size slide

  14. 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ΞΠςϜͷઃఆ

    View full-size slide

  15. Ұ౓࣮ߦͯ͠ΈΔ

    View full-size slide

  16. $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

    View full-size slide

  17. $POpHVSBUJPOΞΠςϜͷ௥Ճ

    View full-size slide

  18. #BSͷ৭ͷΧελϚΠζ
    override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.backgroundColor = UIColor.redColor()
    self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
    }
    4IBSF7JFX$POUSPMMFSTXJGU

    View full-size slide

  19. #BSͷ৭ͷΧελϚΠζ

    View full-size slide

  20. ೖྗνΣοΫ
    override func isContentValid() -> Bool {
    if(self.contentText.isEmpty){
    return false
    }
    return true
    }
    4IBSF7JFX$POUSPMMFSTXJGU

    View full-size slide

  21. ೖྗνΣοΫ

    View full-size slide

  22. 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)
    }
    })
    }
    }

    View full-size slide

  23. ίϯςφʔΞϓϦͱ4IBSF&YUFOTJPOͷ

    σʔλڞ༗
    w ίϯςφΞϓϦͱ&YUFOTJPOͱ͸ผͷλʔήοτͳ
    ͷͰɺ૬ޓͷσʔλΛࢀর͢Δ͜ͱ͸Ͱ͖ͳ͍
    w ,FZDIBJOͷ৔߹͸,FZDIBJO4IBSJOHͱ͍͏ڞ༗ํ
    ๏͕͋Δɻ

    $PSF%BUBͷ৔߹͸"QQ(SPVQͰσʔλڞ༗Ͱ͖
    Δɻ

    View full-size slide

  24. ,FZDIBJO4IBSJOH

    View full-size slide

  25. ,FZDIBJO4IBSJOH

    View full-size slide

  26. ίϯςφʔΞϓϦͰ,FZDIBJOొ࿥
    UICKeyChainStore.setString("xx0123456789xx", forKey: "accessToken" , service: "chat",
    accessGroup: "com.chatwork.inhouse.hogehogehoge")
    7JFX$POUSPMMFSTXJGU

    View full-size slide

  27. &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

    View full-size slide

  28. 6*7JFX$POUSPMMFSΛ࢖͏৔߹

    View full-size slide

  29. ԿͰ΋Ͱ͖ΔͷͰׂѪ

    View full-size slide