Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #146 - 인스타그램 스토리 공유 기능 구현 #171

Merged
merged 9 commits into from
Jan 21, 2022
12 changes: 12 additions & 0 deletions Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
EB9C509827931E4600588155 /* AuthUploadVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB9C509727931E4600588155 /* AuthUploadVC.swift */; };
EB9C509A27931E5F00588155 /* AuthUpload.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB9C509927931E5F00588155 /* AuthUpload.storyboard */; };
EBA2D6CF2799EAFE0022DFD6 /* UIImage+.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA2D6CE2799EAFD0022DFD6 /* UIImage+.swift */; };
EBA2D6D4279AB50D0022DFD6 /* ViewForRender.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA2D6D3279AB50D0022DFD6 /* ViewForRender.swift */; };
EBA77239278A2E14002958A5 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EBA77238278A2E14002958A5 /* Colors.xcassets */; };
EBA93A7D27907EF9009AE771 /* CodeJoinVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA93A7C27907EF9009AE771 /* CodeJoinVC.swift */; };
EBA93A7F279080E2009AE771 /* JoinCheckVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBA93A7E279080E2009AE771 /* JoinCheckVC.swift */; };
Expand Down Expand Up @@ -214,6 +215,7 @@
EB9C509727931E4600588155 /* AuthUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthUploadVC.swift; sourceTree = "<group>"; };
EB9C509927931E5F00588155 /* AuthUpload.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AuthUpload.storyboard; sourceTree = "<group>"; };
EBA2D6CE2799EAFD0022DFD6 /* UIImage+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+.swift"; sourceTree = "<group>"; };
EBA2D6D3279AB50D0022DFD6 /* ViewForRender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewForRender.swift; sourceTree = "<group>"; };
EBA77238278A2E14002958A5 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
EBA93A7C27907EF9009AE771 /* CodeJoinVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeJoinVC.swift; sourceTree = "<group>"; };
EBA93A7E279080E2009AE771 /* JoinCheckVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinCheckVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -618,6 +620,14 @@
path = AuthUpload;
sourceTree = "<group>";
};
EBA2D6D0279AB4BB0022DFD6 /* CompleteAuth */ = {
isa = PBXGroup;
children = (
EBA2D6D3279AB50D0022DFD6 /* ViewForRender.swift */,
);
path = CompleteAuth;
sourceTree = "<group>";
};
EBA93A80279080FC009AE771 /* CodeJoin */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -779,6 +789,7 @@
F8096F1D27841DB600B71D38 /* Views */ = {
isa = PBXGroup;
children = (
EBA2D6D0279AB4BB0022DFD6 /* CompleteAuth */,
2BBFEFBD279ABBD900C085E4 /* HabitRoom */,
2B98520C2790ADDC00CE40A7 /* CreateAuth */,
);
Expand Down Expand Up @@ -1182,6 +1193,7 @@
2BBED13527956EAB0052CA5C /* FeedAPI.swift in Sources */,
F80A3E55278C1C1F00728E07 /* StorageVC.swift in Sources */,
F82F580C27929F74003E4174 /* Header.swift in Sources */,
EBA2D6D4279AB50D0022DFD6 /* ViewForRender.swift in Sources */,
F8E3496827969B61001B67E7 /* AuthAPI.swift in Sources */,
F8096F3C2784211D00B71D38 /* UIColor+.swift in Sources */,
2BE5D818279330A6007A544D /* TimerAuthView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ extension AuthUploadVC {
popupVC.roomName = authUpload.roomName
popupVC.nickName = authUpload.nickname
popupVC.profileImage = authUpload.profileImg
popupVC.timerCount = self.timerLabel.text

popupVC.vcType = self.vcType
popupVC.modalTransitionStyle = .crossDissolve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class CodeJoinVC: UIViewController {
super.viewDidLoad()
setUI()
setAddTargets()
setNotification()
setDelegate()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setNotification()
resetUI()
resetLayout()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CompleteAuthVC: UIViewController {
var roomName: String?
var nickName: String?
var profileImage: String?
var timerCount: String?
let viewForRender = ViewForRender()

// MARK: - Properties
lazy var confettiView: AnimationView = {
Expand Down Expand Up @@ -65,6 +67,22 @@ extension CompleteAuthVC {
tabBarController?.tabBar.isHidden = true

instaView.layer.cornerRadius = 2

viewForRender.roomNameLabel.text = roomName
viewForRender.nickNameLabel.text = nickName
viewForRender.timerLabel.text = timerCount
viewForRender.authImageView.image = renderedImage
viewForRender.profileImageView.updateImage(profileImage ?? "")
}

private func setLayout() {
self.view.addSubview(viewForRender)

viewForRender.snp.makeConstraints { make in
make.width.equalTo(328)
make.height.equalTo(478)
make.trailing.equalToSuperview().inset(-1000)
}
}

private func setGesture() {
Expand All @@ -79,42 +97,35 @@ extension CompleteAuthVC {
}
}

// TODO: 인스타 공유 부분
// func backgroundImage(backgroundImage: UIImage) {
// if let storyShareURL = URL(string: "instagram-stories://share") {
// if UIApplication.shared.canOpenURL(storyShareURL) {
// guard let imageData = backgroundImage.pngData() else {return}
//
// let renderer = UIGraphicsImageRenderer(size: handImageVIew.bounds.size)
//
// let renderImage = renderer.image { _ in
// handImageVIew.drawHierarchy(in: handImageVIew.bounds, afterScreenUpdates: true)
// }
//
// let pasteboardItems : [String:Any] = [
// "com.instagram.sharedSticker.stickerImage": imageData,
// "com.instagram.sharedSticker.backgroundTopColor": "#636e72",
// "com.instagram.sharedSticker.backgroundBottomColor": "#b2bec3"
// ]
//
// let pasteboardOptions = [
// UIPasteboard.OptionsKey.expirationDate: Date().addingTimeInterval(300)
// ]
//
// UIPasteboard.general.setItems([pasteboardItems], options: pasteboardOptions)
//
// UIApplication.shared.open(storyShareURL, options: [:], completionHandler: nil)
//
// } else {
// print("인스타 앱이 깔려있지 않습니다.")
// }
// }
// }
private func shareAuthWithInstagram() {
let renderer = UIGraphicsImageRenderer(size: viewForRender.bounds.size)
let renderImage = renderer.image { _ in
viewForRender.drawHierarchy(in: viewForRender.bounds, afterScreenUpdates: true)
}

if let storyShareURL = URL(string: "instagram-stories://share") {
if UIApplication.shared.canOpenURL(storyShareURL) {
guard let imageData = renderImage.pngData() else {return}

let pasteboardItems: [String: Any] = [
"com.instagram.sharedSticker.stickerImage": imageData,
"com.instagram.sharedSticker.backgroundTopColor": "#8D8D88",
"com.instagram.sharedSticker.backgroundBottomColor": "#8D8D88"]

let pasteboardOptions = [UIPasteboard.OptionsKey.expirationDate: Date().addingTimeInterval(300)]

UIPasteboard.general.setItems([pasteboardItems], options: pasteboardOptions)
UIApplication.shared.open(storyShareURL, options: [:], completionHandler: nil)
} else {
print("인스타 앱이 깔려있지 않습니다.")
}
}
}

// MARK: - @objc
@objc
func tapped(_ gesture: UITapGestureRecognizer) {
// 인스타 공유 기능
// backgroundImage(backgroundImage: renderedImage ?? UIImage())
setLayout()
shareAuthWithInstagram()
}
}
115 changes: 115 additions & 0 deletions Spark-iOS/Spark-iOS/Source/Views/CompleteAuth/ViewForRender.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// ViewForRender.swift
// Spark-iOS
//
// Created by Junho Lee on 2022/01/21.
//
import UIKit

import SnapKit

class ViewForRender: UIView {

// MARK: - Properties
let roomNameLabel = UILabel()
let nickNameLabel = UILabel()
let profileImageView = UIImageView()
let authImageView = UIImageView()
let stickerImageView = UIImageView()
let timerLabel = UILabel()
let largeView = UIView()

// MARK: - View Life Cycle
override init(frame: CGRect) {
super.init(frame: frame)

setUI()
setLayout()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Methods
/// 기본 UI
func setUI() {

self.backgroundColor = .clear
self.isOpaque = true

largeView.backgroundColor = .sparkWhite
largeView.layer.cornerRadius = 2

stickerImageView.image = UIImage(named: "stickerCompleteDefault")

authImageView.contentMode = .scaleAspectFill
authImageView.layer.masksToBounds = true

timerLabel.text = " "
timerLabel.font = .enBoldFont(ofSize: 40)
timerLabel.textColor = .sparkWhite

nickNameLabel.text = " "
roomNameLabel.font = .enBoldFont(ofSize: 16)
nickNameLabel.textColor = .sparkDeepGray
nickNameLabel.font = .p1Title

roomNameLabel.text = " "
roomNameLabel.font = .enBoldFont(ofSize: 20)
roomNameLabel.textColor = .sparkDeepGray

profileImageView.image = UIImage(named: "stickerPhotoDefault")
profileImageView.layer.cornerRadius = 32
profileImageView.layer.borderColor = UIColor.sparkWhite.cgColor
profileImageView.layer.borderWidth = 2
profileImageView.clipsToBounds = true
profileImageView.layer.masksToBounds = true

self.layer.cornerRadius = 2
}

func setLayout() {
addSubviews([largeView, stickerImageView])

largeView.addSubviews([authImageView, timerLabel, profileImageView,
nickNameLabel, roomNameLabel])

largeView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.leading.trailing.bottom.equalToSuperview()
make.top.equalToSuperview().offset(38)
}

stickerImageView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview()
make.width.height.equalTo(96)
}

authImageView.snp.makeConstraints { make in
make.top.leading.equalToSuperview().inset(8)
make.width.height.equalTo(312)
}

timerLabel.snp.makeConstraints { make in
make.centerX.centerY.equalTo(authImageView)
}

profileImageView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.width.height.equalTo(64)
make.centerY.equalTo(authImageView.snp.bottom)
}

nickNameLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(profileImageView.snp.bottom).offset(3)
}

roomNameLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(nickNameLabel.snp.bottom).offset(15)
}
}
}