Skip to content

Commit

Permalink
Merge pull request #492 from hyun99999/feature/#470
Browse files Browse the repository at this point in the history
feat: 위젯 통해서 앱 열기 (#470)
  • Loading branch information
hyun99999 authored May 8, 2023
2 parents 4a6ebe4 + d319c7f commit 4f784ef
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 85 deletions.
72 changes: 41 additions & 31 deletions IntentsExtension/IntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,61 @@ class IntentHandler: INExtension {
// This is the default implementation. If you want different objects to handle different intents,
// you can override this and return the handler you want for that particular intent.

cardListFetchWithAPI { [weak self] result in
switch result {
case .success(let result):
if let result {
self?.cardItems = result.data
print(self?.cardItems)
}
case .failure(let err):
print(err)
}
}

return self
}
}

extension IntentHandler: MyCardIntentHandling {
// 내 명함 목록 선택할 때 호출.
func provideMyCardOptionsCollection(for intent: MyCardIntent, with completion: @escaping (INObjectCollection<MyCard>?, Error?) -> Void) {
cardListFetchWithAPI { [weak self] result in
cardListFetchWithAPI { result in
switch result {
case .success(let result):
if let result {
self?.cardItems = result.data

if let cardItems = self?.cardItems {
let myCards = cardItems.map { card in
let myCard = MyCard(identifier: card.cardUUID, display: card.cardName)
myCard.userName = card.userName
myCard.cardImage = card.cardImage

return myCard
}
let collection = INObjectCollection(items: myCards)
completion(collection, nil)
if let cardItems = result?.data {
let myCards = cardItems.map { card in
let myCard = MyCard(identifier: card.cardUUID, display: card.cardName)
myCard.userName = card.userName
myCard.cardImage = card.cardImage

return myCard
}
let collection = INObjectCollection(items: myCards)
completion(collection, nil)
}
case .failure(let err):
print(err)
completion(nil, nil)
}
}
}

// 위젯 편집할때 호출. 기본값 설정.
// 위젯 추가할때 호출. 기본값 설정.
func defaultMyCard(for intent: MyCardIntent) -> MyCard? {
var myCard: MyCard?

if let cardItems {
myCard = MyCard(identifier: cardItems[0].cardUUID, display: cardItems[0].cardName)
let group = DispatchGroup()

DispatchQueue.global().async(group: group) { [weak self] in
group.enter()

self?.cardListFetchWithAPI { [weak self] result in
switch result {
case .success(let result):
if let result {
self?.cardItems = result.data
myCard = MyCard(identifier: self?.cardItems?[0].cardUUID ?? "", display: self?.cardItems?[0].cardName ?? "")
myCard?.userName = self?.cardItems?[0].userName
myCard?.cardImage = self?.cardItems?[0].cardImage
}
case .failure(let err):
print(err)
}
group.leave()
}
}

_ = group.wait(timeout: .now() + 60)

return myCard
}
}
Expand All @@ -85,7 +89,7 @@ extension IntentHandler {
guard let url = URL(string: "http://3.35.107.3:8080/api/v1/card") else { return }
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "GET"
urlRequest.addValue("Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjEwfQ.rq__Rzvunpxq3paeo2fK4i_oeupyDlHp3q1RW6uSHSQ", forHTTPHeaderField: "Authorization")
urlRequest.addValue("Bearer \(UserDefaults.appGroup.string(forKey: "accessToken") ?? "")", forHTTPHeaderField: "Authorization")
print("😀", UserDefaults.appGroup.string(forKey: "accessToken") ?? "")

URLSession.shared.dataTask(with: urlRequest) { data, response, error in
Expand All @@ -103,7 +107,13 @@ extension IntentHandler {
message: result?.message ?? "none message")))
} else {
if let result {
completion(.success(result))
if result.status != 200 {
completion(.failure(WidgetError.networkFail(status: status,
code: result.code ?? "none code",
message: result.message ?? "none message")))
} else {
completion(.success(result))
}
} else {
completion(.failure(WidgetError.decodeFail(status: status)))
}
Expand Down
34 changes: 17 additions & 17 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 53;
objects = {

/* Begin PBXBuildFile section */
2566DBA723D1370275ECE593 /* Pods_NADA_iOS_forRelease.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D86FBA2B7966CFE6EEF0E7E8 /* Pods_NADA_iOS_forRelease.framework */; };
39007F2C27080D8200E7143E /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39007F2B27080D8200E7143E /* UIViewController+Extension.swift */; };
3903CC202769F4F40094C458 /* EmptyCardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3903CC1E2769F4F40094C458 /* EmptyCardCell.swift */; };
3903CC212769F4F40094C458 /* EmptyCardCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3903CC1F2769F4F40094C458 /* EmptyCardCell.xib */; };
Expand Down Expand Up @@ -218,6 +217,7 @@
F8FC43BA26C022900033E151 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43B926C022900033E151 /* ViewController.swift */; };
F8FC43BC26C022A20033E151 /* Storyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FC43BB26C022A20033E151 /* Storyboard.swift */; };
F8FC43BF26C025180033E151 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = F8FC43BE26C025180033E151 /* .swiftlint.yml */; };
FF46241630BB3F2D09D5A1AF /* Pods_NADA_iOS_forRelease.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F6A2AA0066BA1941116A267 /* Pods_NADA_iOS_forRelease.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -261,7 +261,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
00BC6C525F13C9651D73976F /* Pods-NADA-iOS-forRelease.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NADA-iOS-forRelease.debug.xcconfig"; path = "Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease.debug.xcconfig"; sourceTree = "<group>"; };
0F6A2AA0066BA1941116A267 /* Pods_NADA_iOS_forRelease.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NADA_iOS_forRelease.framework; sourceTree = BUILT_PRODUCTS_DIR; };
13B19E918E93248BE054C89A /* Pods-NADA-iOS-forRelease.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NADA-iOS-forRelease.debug.xcconfig"; path = "Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease.debug.xcconfig"; sourceTree = "<group>"; };
19298D75B81F3260A870AB0B /* Pods-NADA-iOS-forRelease.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NADA-iOS-forRelease.release.xcconfig"; path = "Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease.release.xcconfig"; sourceTree = "<group>"; };
39007F2B27080D8200E7143E /* UIViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = "<group>"; };
3903CC1E2769F4F40094C458 /* EmptyCardCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCardCell.swift; sourceTree = "<group>"; };
3903CC1F2769F4F40094C458 /* EmptyCardCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EmptyCardCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -371,15 +373,12 @@
77F2C0EA27632A91007641E3 /* CardHarmonyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardHarmonyViewController.swift; sourceTree = "<group>"; };
77F2C0EC27632AA7007641E3 /* CardHarmony.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CardHarmony.storyboard; sourceTree = "<group>"; };
77F47D92276C79B600414659 /* Header.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Header.swift; sourceTree = "<group>"; };
78FC1ADEA3CAB995C08D47DB /* Pods-NADA-iOS-forRelease.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NADA-iOS-forRelease.release.xcconfig"; path = "Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease.release.xcconfig"; sourceTree = "<group>"; };
D86FBA2B7966CFE6EEF0E7E8 /* Pods_NADA_iOS_forRelease.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NADA_iOS_forRelease.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F805588429C993E7002E8EA3 /* UpdateViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateViewController.swift; sourceTree = "<group>"; };
F80C679129F21BB7002C5ECC /* onboarding01.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = onboarding01.json; sourceTree = "<group>"; };
F80C679229F21BB7002C5ECC /* onboarding02.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = onboarding02.json; sourceTree = "<group>"; };
F81171FF27383097002742CF /* ChangeGroupRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeGroupRequest.swift; sourceTree = "<group>"; };
F822E7A82709CEB60020452C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
F8268DB827730B0100BF114B /* FirstCardAlertBottomSheetViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstCardAlertBottomSheetViewController.swift; sourceTree = "<group>"; };
F82AF6A029FBBAF50051545B /* IntentsExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = IntentsExtension.entitlements; sourceTree = "<group>"; };
F82AF6A129FBBEE50051545B /* UserDefaults+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Extension.swift"; sourceTree = "<group>"; };
F82FEB4A27639F3100DA7847 /* MainCardCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainCardCell.swift; sourceTree = "<group>"; };
F82FEB4B27639F3100DA7847 /* MainCardCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainCardCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -510,7 +509,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2566DBA723D1370275ECE593 /* Pods_NADA_iOS_forRelease.framework in Frameworks */,
FF46241630BB3F2D09D5A1AF /* Pods_NADA_iOS_forRelease.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -520,8 +519,8 @@
186051B2C99DBAECC539DAC9 /* Pods */ = {
isa = PBXGroup;
children = (
00BC6C525F13C9651D73976F /* Pods-NADA-iOS-forRelease.debug.xcconfig */,
78FC1ADEA3CAB995C08D47DB /* Pods-NADA-iOS-forRelease.release.xcconfig */,
13B19E918E93248BE054C89A /* Pods-NADA-iOS-forRelease.debug.xcconfig */,
19298D75B81F3260A870AB0B /* Pods-NADA-iOS-forRelease.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
Expand Down Expand Up @@ -748,7 +747,7 @@
F838B661298E5C5300D84340 /* SwiftUI.framework */,
F87D2229298ECAFB001A882B /* Intents.framework */,
F87D2234298ECAFB001A882B /* IntentsUI.framework */,
D86FBA2B7966CFE6EEF0E7E8 /* Pods_NADA_iOS_forRelease.framework */,
0F6A2AA0066BA1941116A267 /* Pods_NADA_iOS_forRelease.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -1517,13 +1516,13 @@
isa = PBXNativeTarget;
buildConfigurationList = F8FC439626C01CDE0033E151 /* Build configuration list for PBXNativeTarget "NADA-iOS-forRelease" */;
buildPhases = (
63B126249E7D65994A592714 /* [CP] Check Pods Manifest.lock */,
968E60C36CA3B9A2790CB1AA /* [CP] Check Pods Manifest.lock */,
F8FC437E26C01CDD0033E151 /* Sources */,
F8FC437F26C01CDD0033E151 /* Frameworks */,
F8FC438026C01CDD0033E151 /* Resources */,
F8FC43BD26C0244D0033E151 /* ShellScript */,
F838B673298E5C5400D84340 /* Embed Foundation Extensions */,
2FD8F2B3BF35A3CA09A8E81C /* [CP] Embed Pods Frameworks */,
3DFB37457B9A5C839910082B /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -1543,8 +1542,9 @@
F8FC437A26C01CDD0033E151 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1430;
TargetAttributes = {
F838B65D298E5C5300D84340 = {
CreatedOnToolsVersion = 14.2;
Expand Down Expand Up @@ -1669,7 +1669,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
2FD8F2B3BF35A3CA09A8E81C /* [CP] Embed Pods Frameworks */ = {
3DFB37457B9A5C839910082B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -1686,7 +1686,7 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
63B126249E7D65994A592714 /* [CP] Check Pods Manifest.lock */ = {
968E60C36CA3B9A2790CB1AA /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down Expand Up @@ -2278,7 +2278,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = "YJC.NADA-iOS-forRelease";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "match Development YJC.NADA-iOS-forRelease";
Expand Down Expand Up @@ -2307,7 +2307,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = "YJC.NADA-iOS-forRelease";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "match AppStore YJC.NADA-iOS-forRelease";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
8 changes: 4 additions & 4 deletions NADA-iOS-forRelease/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>&quot;사용자의 위치를 받아오려고 합니다.&quot;</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>&quot;사용자의 위치를 받아오려고 합니다.&quot;</string>
<key>CFBundleDevelopmentRegion</key>
<string>ko_KR</string>
<key>CFBundleDisplayName</key>
Expand Down Expand Up @@ -52,6 +48,10 @@
</dict>
<key>NSCameraUsageDescription</key>
<string>QR코드를 인식하여 명함을 추가하기 위해 카메라 권한 허용이 필요해요.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>"사용자의 위치를 받아오려고 합니다."</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>"사용자의 위치를 받아오려고 합니다."</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>명함을 이미지로 저장하기 위해 갤러리 권한 허용이 필요해요.</string>
<key>NSPhotoLibraryUsageDescription</key>
Expand Down
8 changes: 5 additions & 3 deletions NADA-iOS-forRelease/Resouces/Constants/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ extension Const {
static let darkModeState = "darkModeState"
static let userID = "userID"
static let isFirstCard = "isFirstCard"
static let isOnboarding = "isOnboarding"
static let isOnboarding = "isOnboardingAvailable"
static let firstCardID = "firstCardID"
static let isAppleLogin = "isAppleLogin"
static let isKakaoLogin = "isKakaoLogin"
static let dynamicLinkCardUUID = "dynamicLinkCardUUID"
// TODO: - KeyChain 적용
static let accessToken = "accessToken"
static let accessToken = "AccessToken"
static let openQRCodeWidget = "openQRCodeWidget"
static let openMyCardWidget = "openMyCardWidget"
static let widgetCardUUID = "widgetCardUUID"
static let refreshToken = "refreshToken"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

extension UserDefaults {
static var appGroup = UserDefaults(suiteName: "group.NADA-iOS-forRelease")!
static var appGroup = UserDefaults(suiteName: "group.YJC.NADA-iOS-forRelease")!
}
Loading

0 comments on commit 4f784ef

Please sign in to comment.