generated from dannaward/create-ios-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #227 - 갤러리에서 바로 공유 구현
- Loading branch information
Showing
10 changed files
with
443 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="j1y-V4-xli"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Share View Controller--> | ||
<scene sceneID="ceB-am-kn3"> | ||
<objects> | ||
<viewController id="j1y-V4-xli" customClass="ShareViewController" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/> | ||
<viewLayoutGuide key="safeArea" id="1Xd-am-t49"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSAppTransportSecurity</key> | ||
<dict> | ||
<key>NSAllowsArbitraryLoads</key> | ||
<true/> | ||
</dict> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>NSExtensionActivationRule</key> | ||
<dict> | ||
<key>NSExtensionActivationSupportsImageWithMaxCount</key> | ||
<integer>1</integer> | ||
</dict> | ||
</dict> | ||
<key>NSExtensionMainStoryboard</key> | ||
<string>MainInterface</string> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.share-services</string> | ||
</dict> | ||
<key>UIAppFonts</key> | ||
<array> | ||
<string>Pretendard-Regular.otf</string> | ||
<string>Pretendard-Medium.otf</string> | ||
<string>Pretendard-SemiBold.otf</string> | ||
<string>Pretendard-Bold.otf</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>group.Team.pophory-iOS</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// ShareViewController.swift | ||
// ShareExtension | ||
// | ||
// Created by 김다예 on 2023/09/27. | ||
// | ||
|
||
import UIKit | ||
import Social | ||
import UniformTypeIdentifiers | ||
|
||
final class ShareViewController: UIViewController { | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
|
||
guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem, | ||
let itemProvider = extensionItem.attachments?.first else { | ||
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil) | ||
return | ||
} | ||
handleIncomingText(itemProvider: itemProvider) | ||
} | ||
|
||
private func handleIncomingText(itemProvider: NSItemProvider) { | ||
if itemProvider.canLoadObject(ofClass: UIImage.self) { // itemProvider가 불러온 이미지 값 가져올 수 있다면 실행 | ||
|
||
itemProvider.loadObject(ofClass: UIImage.self) { image, error in | ||
self.extensionContext?.completeRequest(returningItems: nil) { _ in | ||
guard let url = URL(string: "pophoryiOS://share") else { return } | ||
|
||
self.openURL(url) | ||
UIPasteboard.general.image = image as? UIImage | ||
} | ||
} | ||
} | ||
} | ||
|
||
@objc | ||
@discardableResult | ||
func openURL(_ url: URL) -> Bool { | ||
var responder: UIResponder? = self | ||
while responder != nil { | ||
if let application = responder as? UIApplication { | ||
return application.perform(#selector(openURL(_:)), with: url) != nil | ||
} | ||
responder = responder?.next | ||
} | ||
return false | ||
} | ||
} |
Oops, something went wrong.