diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57968a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.DS_Store + +## User settings +xcuserdata/ + +## Schemes +xcschemes/ + +## CocoaPods +Pods/ diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..fa5f0f3 --- /dev/null +++ b/Podfile @@ -0,0 +1,6 @@ +platform :ios, '13.0' +use_frameworks! + +target 'end-user-api-demo' do + pod 'OAuthSwift', '~> 2.1.0' +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..737f4f1 --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,16 @@ +PODS: + - OAuthSwift (2.1.0) + +DEPENDENCIES: + - OAuthSwift (~> 2.1.0) + +SPEC REPOS: + trunk: + - OAuthSwift + +SPEC CHECKSUMS: + OAuthSwift: ab1675598273e04355e0282459c328e65c9ddacd + +PODFILE CHECKSUM: 0b0ca8e1954f2da6c291ff1fe6d8382630b9986d + +COCOAPODS: 1.8.4 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b0a99da --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# UserVoice End User API Demo (iOS) + +A simple iOS app to demonstrate the OAuth authentication_code flow and basic functionality of the UserVoice [End User API](https://developer.uservoice.com/). + +> NOTE: This app should only serve as an example for how to use the UserVoice End User API. It is not intended to highlight iOS best practices. + +## Project Dependencies +* [CocoaPods](https://cocoapods.org/): Dependency manager for Swift +* [OAuthSwift](https://github.com/OAuthSwift/OAuthSwift): Swift library for handling the OAuth2 flow + +## Installation (requires Xcode) +1. Clone the repository: `git clone git@github.com:uservoice/end-user-api-ios-demo.git`. +2. Ensure CocoaPods dependency manager is installed: `sudo gem install cocoapods`. +3. Navigate into project directory and install dependencies: `cd end-user-api-ios-demo && pod install`. +4. Create an API key from the UserVoice admin console and set the "Callback URL" to `com.uv.Demo:/oauth2Callback`. + * For more information on creating an API key and implementing the OAuth flow, see [this guide](https://developer.uservoice.com/docs/end-user-api/auth/). +5. Open `end-user-api-demo.xcworkspace` in Xcode. +6. Set the environment variables referenced at the top of [UvApi.swift](https://github.com/uservoice/end-user-api-ios-demo/blob/master/end-user-api-demo/UvApi.swift) by configuring the Xcode Scheme. +7. Build and run the app. + +## Resources +* [UserVoice End User API Reference](https://developer.uservoice.com/docs/end-user-api/reference/) +* [OAuth Authentication Code Flow with PKCE](https://developer.uservoice.com/docs/end-user-api/auth/) +* [OAuthSwift](https://github.com/OAuthSwift/OAuthSwift) diff --git a/end-user-api-demo.xcodeproj/project.pbxproj b/end-user-api-demo.xcodeproj/project.pbxproj new file mode 100644 index 0000000..02c3512 --- /dev/null +++ b/end-user-api-demo.xcodeproj/project.pbxproj @@ -0,0 +1,682 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 33303F9123ABD00C00FC5982 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33303F9023ABD00C00FC5982 /* Types.swift */; }; + 33303F9923ABEB8200FC5982 /* ForumVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33303F9823ABEB8200FC5982 /* ForumVC.swift */; }; + 3343382A23C3892E00CD39A5 /* IdeaDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3343382923C3892E00CD39A5 /* IdeaDetailVC.swift */; }; + 33462E5923A2E06F0007A46D /* HomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33462E5823A2E06F0007A46D /* HomeVC.swift */; }; + 33462E5B23A2E4930007A46D /* UvApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33462E5A23A2E4930007A46D /* UvApi.swift */; }; + 33536DCD23A2CDAC00D00606 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33536DCC23A2CDAC00D00606 /* AppDelegate.swift */; }; + 33536DCF23A2CDAC00D00606 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33536DCE23A2CDAC00D00606 /* SceneDelegate.swift */; }; + 33536DD423A2CDAC00D00606 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 33536DD223A2CDAC00D00606 /* Main.storyboard */; }; + 33536DD623A2CDAE00D00606 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33536DD523A2CDAE00D00606 /* Assets.xcassets */; }; + 33536DD923A2CDAE00D00606 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 33536DD723A2CDAE00D00606 /* LaunchScreen.storyboard */; }; + 33DEE20223D0F01100726E16 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DEE20123D0F01100726E16 /* Extensions.swift */; }; + ECE719813510952AFFE3A7A0 /* Pods_end_user_api_demo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0836AB952E17E35B372A9F74 /* Pods_end_user_api_demo.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 334DB2EA23CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = F435027A1A6791B200038A29; + remoteInfo = OAuthSwift; + }; + 334DB2EC23CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C48B28021AFA598D00C7DEF6; + remoteInfo = OAuthSwiftMacOS; + }; + 334DB2EE23CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C4B6EE1E1BF74CE300443596; + remoteInfo = OAuthSwiftTVOS; + }; + 334DB2F023CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C40890C01C11B37000E3146A; + remoteInfo = OAuthSwiftWatchOS; + }; + 334DB2F223CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = F451E3C5195B8CD80051434C; + remoteInfo = OAuthSwiftDemo; + }; + 334DB2F423CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C49FD5241AFB5DF500791E1A; + remoteInfo = OAuthSwiftMacOSDemo; + }; + 334DB2F623CE641800F0385E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C4D50DF71BFB693F0053B624; + remoteInfo = OAuthSwiftTests; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 0836AB952E17E35B372A9F74 /* Pods_end_user_api_demo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_end_user_api_demo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 209440FC0AE6F47AAFFCAF0D /* Pods-end-user-api-demo.development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-end-user-api-demo.development.xcconfig"; path = "Pods/Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo.development.xcconfig"; sourceTree = ""; }; + 33303F9023ABD00C00FC5982 /* Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = ""; }; + 33303F9823ABEB8200FC5982 /* ForumVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForumVC.swift; sourceTree = ""; }; + 3343382923C3892E00CD39A5 /* IdeaDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdeaDetailVC.swift; sourceTree = ""; }; + 33462E5823A2E06F0007A46D /* HomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeVC.swift; sourceTree = ""; }; + 33462E5A23A2E4930007A46D /* UvApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UvApi.swift; sourceTree = ""; }; + 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OAuthSwift.xcodeproj; path = "../../Downloads/OAuthSwift-2.1.0/OAuthSwift.xcodeproj"; sourceTree = ""; }; + 33536DC923A2CDAC00D00606 /* end-user-api-demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "end-user-api-demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33536DCC23A2CDAC00D00606 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33536DCE23A2CDAC00D00606 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 33536DD323A2CDAC00D00606 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 33536DD523A2CDAE00D00606 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 33536DD823A2CDAE00D00606 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 33536DDA23A2CDAE00D00606 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 33DEE20123D0F01100726E16 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; + 394430454AFE827C5B6F2D6E /* Pods-end-user-api-demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-end-user-api-demo.debug.xcconfig"; path = "Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo.debug.xcconfig"; sourceTree = ""; }; + 777E22E816ACF6BBECE73030 /* Pods-end-user-api-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-end-user-api-demo.release.xcconfig"; path = "Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo.release.xcconfig"; sourceTree = ""; }; + A3DA496084474AF8230E34A3 /* Pods-end-user-api-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-end-user-api-demo.release.xcconfig"; path = "Pods/Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo.release.xcconfig"; sourceTree = ""; }; + DC8801839F1BAB4401F8DCDC /* Pods-end-user-api-demo.development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-end-user-api-demo.development.xcconfig"; path = "Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo.development.xcconfig"; sourceTree = ""; }; + F564858AE7BE9C0EE003703E /* Pods-end-user-api-demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-end-user-api-demo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo.debug.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33536DC623A2CDAC00D00606 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ECE719813510952AFFE3A7A0 /* Pods_end_user_api_demo.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 334DB2E123CE641800F0385E /* Products */ = { + isa = PBXGroup; + children = ( + 334DB2EB23CE641800F0385E /* OAuthSwift.framework */, + 334DB2ED23CE641800F0385E /* OAuthSwift.framework */, + 334DB2EF23CE641800F0385E /* OAuthSwift.framework */, + 334DB2F123CE641800F0385E /* OAuthSwift.framework */, + 334DB2F323CE641800F0385E /* OAuthSwiftDemo.app */, + 334DB2F523CE641800F0385E /* OAuthSwiftMacOSDemo.app */, + 334DB2F723CE641800F0385E /* OAuthSwiftTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 33536DC023A2CDAC00D00606 = { + isa = PBXGroup; + children = ( + 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */, + 33536DCB23A2CDAC00D00606 /* end-user-api-demo */, + 33536DCA23A2CDAC00D00606 /* Products */, + 6FC7363ED55489CF6562D837 /* Pods */, + 378824D56856BCCA7233E437 /* Frameworks */, + ); + sourceTree = ""; + }; + 33536DCA23A2CDAC00D00606 /* Products */ = { + isa = PBXGroup; + children = ( + 33536DC923A2CDAC00D00606 /* end-user-api-demo.app */, + ); + name = Products; + sourceTree = ""; + }; + 33536DCB23A2CDAC00D00606 /* end-user-api-demo */ = { + isa = PBXGroup; + children = ( + 33DEE1B923CF945700726E16 /* Delegates */, + 33DEE1B823CF932200726E16 /* Storyboards */, + 33DEE1B723CF931100726E16 /* Resources */, + 33DEE1B023CF92FF00726E16 /* Config */, + 33536DE023A2CDDF00D00606 /* ViewControllers */, + 33462E5A23A2E4930007A46D /* UvApi.swift */, + 33303F9023ABD00C00FC5982 /* Types.swift */, + 33DEE20123D0F01100726E16 /* Extensions.swift */, + ); + path = "end-user-api-demo"; + sourceTree = ""; + }; + 33536DE023A2CDDF00D00606 /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 33462E5823A2E06F0007A46D /* HomeVC.swift */, + 33303F9823ABEB8200FC5982 /* ForumVC.swift */, + 3343382923C3892E00CD39A5 /* IdeaDetailVC.swift */, + ); + path = ViewControllers; + sourceTree = ""; + }; + 33DEE1B023CF92FF00726E16 /* Config */ = { + isa = PBXGroup; + children = ( + 33536DDA23A2CDAE00D00606 /* Info.plist */, + ); + path = Config; + sourceTree = ""; + }; + 33DEE1B723CF931100726E16 /* Resources */ = { + isa = PBXGroup; + children = ( + 33536DD523A2CDAE00D00606 /* Assets.xcassets */, + ); + path = Resources; + sourceTree = ""; + }; + 33DEE1B823CF932200726E16 /* Storyboards */ = { + isa = PBXGroup; + children = ( + 33536DD723A2CDAE00D00606 /* LaunchScreen.storyboard */, + 33536DD223A2CDAC00D00606 /* Main.storyboard */, + ); + path = Storyboards; + sourceTree = ""; + }; + 33DEE1B923CF945700726E16 /* Delegates */ = { + isa = PBXGroup; + children = ( + 33536DCC23A2CDAC00D00606 /* AppDelegate.swift */, + 33536DCE23A2CDAC00D00606 /* SceneDelegate.swift */, + ); + path = Delegates; + sourceTree = ""; + }; + 378824D56856BCCA7233E437 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 0836AB952E17E35B372A9F74 /* Pods_end_user_api_demo.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 6FC7363ED55489CF6562D837 /* Pods */ = { + isa = PBXGroup; + children = ( + 394430454AFE827C5B6F2D6E /* Pods-end-user-api-demo.debug.xcconfig */, + DC8801839F1BAB4401F8DCDC /* Pods-end-user-api-demo.development.xcconfig */, + 777E22E816ACF6BBECE73030 /* Pods-end-user-api-demo.release.xcconfig */, + F564858AE7BE9C0EE003703E /* Pods-end-user-api-demo.debug.xcconfig */, + 209440FC0AE6F47AAFFCAF0D /* Pods-end-user-api-demo.development.xcconfig */, + A3DA496084474AF8230E34A3 /* Pods-end-user-api-demo.release.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33536DC823A2CDAC00D00606 /* end-user-api-demo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33536DDD23A2CDAE00D00606 /* Build configuration list for PBXNativeTarget "end-user-api-demo" */; + buildPhases = ( + 930DE959D69A6BD9166E1411 /* [CP] Check Pods Manifest.lock */, + 33536DC523A2CDAC00D00606 /* Sources */, + 33536DC623A2CDAC00D00606 /* Frameworks */, + 33536DC723A2CDAC00D00606 /* Resources */, + BBB3D3D83E64B9DAE724CC01 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "end-user-api-demo"; + productName = "end-user-api-demo2"; + productReference = 33536DC923A2CDAC00D00606 /* end-user-api-demo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33536DC123A2CDAC00D00606 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1110; + LastUpgradeCheck = 1110; + ORGANIZATIONNAME = UserVoice; + TargetAttributes = { + 33536DC823A2CDAC00D00606 = { + CreatedOnToolsVersion = 11.1; + }; + }; + }; + buildConfigurationList = 33536DC423A2CDAC00D00606 /* Build configuration list for PBXProject "end-user-api-demo" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33536DC023A2CDAC00D00606; + productRefGroup = 33536DCA23A2CDAC00D00606 /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 334DB2E123CE641800F0385E /* Products */; + ProjectRef = 334DB2E023CE641800F0385E /* OAuthSwift.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + 33536DC823A2CDAC00D00606 /* end-user-api-demo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + 334DB2EB23CE641800F0385E /* OAuthSwift.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = OAuthSwift.framework; + remoteRef = 334DB2EA23CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 334DB2ED23CE641800F0385E /* OAuthSwift.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = OAuthSwift.framework; + remoteRef = 334DB2EC23CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 334DB2EF23CE641800F0385E /* OAuthSwift.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = OAuthSwift.framework; + remoteRef = 334DB2EE23CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 334DB2F123CE641800F0385E /* OAuthSwift.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = OAuthSwift.framework; + remoteRef = 334DB2F023CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 334DB2F323CE641800F0385E /* OAuthSwiftDemo.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = OAuthSwiftDemo.app; + remoteRef = 334DB2F223CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 334DB2F523CE641800F0385E /* OAuthSwiftMacOSDemo.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = OAuthSwiftMacOSDemo.app; + remoteRef = 334DB2F423CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 334DB2F723CE641800F0385E /* OAuthSwiftTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = OAuthSwiftTests.xctest; + remoteRef = 334DB2F623CE641800F0385E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + 33536DC723A2CDAC00D00606 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33536DD923A2CDAE00D00606 /* LaunchScreen.storyboard in Resources */, + 33536DD623A2CDAE00D00606 /* Assets.xcassets in Resources */, + 33536DD423A2CDAC00D00606 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 930DE959D69A6BD9166E1411 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-end-user-api-demo-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + BBB3D3D83E64B9DAE724CC01 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-end-user-api-demo/Pods-end-user-api-demo-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33536DC523A2CDAC00D00606 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33462E5923A2E06F0007A46D /* HomeVC.swift in Sources */, + 33536DCD23A2CDAC00D00606 /* AppDelegate.swift in Sources */, + 3343382A23C3892E00CD39A5 /* IdeaDetailVC.swift in Sources */, + 33DEE20223D0F01100726E16 /* Extensions.swift in Sources */, + 33303F9123ABD00C00FC5982 /* Types.swift in Sources */, + 33303F9923ABEB8200FC5982 /* ForumVC.swift in Sources */, + 33536DCF23A2CDAC00D00606 /* SceneDelegate.swift in Sources */, + 33462E5B23A2E4930007A46D /* UvApi.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 33536DD223A2CDAC00D00606 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 33536DD323A2CDAC00D00606 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 33536DD723A2CDAE00D00606 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 33536DD823A2CDAE00D00606 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 33536DDB23A2CDAE00D00606 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33536DDC23A2CDAE00D00606 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 33536DDE23A2CDAE00D00606 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 394430454AFE827C5B6F2D6E /* Pods-end-user-api-demo.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "end-user-api-demo/Config/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "uv.end-user-api-demo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 33536DDF23A2CDAE00D00606 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 777E22E816ACF6BBECE73030 /* Pods-end-user-api-demo.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "end-user-api-demo/Config/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "uv.end-user-api-demo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 33DEE1BC23D0B7CE00726E16 /* Development */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Development; + }; + 33DEE1BD23D0B7CE00726E16 /* Development */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = DC8801839F1BAB4401F8DCDC /* Pods-end-user-api-demo.development.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "end-user-api-demo/Config/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "uv.end-user-api-demo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Development; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33536DC423A2CDAC00D00606 /* Build configuration list for PBXProject "end-user-api-demo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33536DDB23A2CDAE00D00606 /* Debug */, + 33DEE1BC23D0B7CE00726E16 /* Development */, + 33536DDC23A2CDAE00D00606 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33536DDD23A2CDAE00D00606 /* Build configuration list for PBXNativeTarget "end-user-api-demo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33536DDE23A2CDAE00D00606 /* Debug */, + 33DEE1BD23D0B7CE00726E16 /* Development */, + 33536DDF23A2CDAE00D00606 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33536DC123A2CDAC00D00606 /* Project object */; +} diff --git a/end-user-api-demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/end-user-api-demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..a08b3da --- /dev/null +++ b/end-user-api-demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/end-user-api-demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/end-user-api-demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/end-user-api-demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/end-user-api-demo.xcodeproj/xcshareddata/IDETemplateMacros.plist b/end-user-api-demo.xcodeproj/xcshareddata/IDETemplateMacros.plist new file mode 100644 index 0000000..8ca2f25 --- /dev/null +++ b/end-user-api-demo.xcodeproj/xcshareddata/IDETemplateMacros.plist @@ -0,0 +1,9 @@ + + + + + FILEHEADER + ___FILENAME___ +// ___PROJECTNAME___ + + diff --git a/end-user-api-demo.xcworkspace/contents.xcworkspacedata b/end-user-api-demo.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..8079a91 --- /dev/null +++ b/end-user-api-demo.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/end-user-api-demo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/end-user-api-demo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/end-user-api-demo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/end-user-api-demo/Config/Info.plist b/end-user-api-demo/Config/Info.plist new file mode 100644 index 0000000..a01cd70 --- /dev/null +++ b/end-user-api-demo/Config/Info.plist @@ -0,0 +1,71 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleURLTypes + + + CFBundleURLSchemes + + com.uv.Demo + + + + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/end-user-api-demo/Delegates/AppDelegate.swift b/end-user-api-demo/Delegates/AppDelegate.swift new file mode 100644 index 0000000..1f7efe3 --- /dev/null +++ b/end-user-api-demo/Delegates/AppDelegate.swift @@ -0,0 +1,31 @@ +// AppDelegate.swift +// end-user-api-demo + + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/end-user-api-demo/Delegates/SceneDelegate.swift b/end-user-api-demo/Delegates/SceneDelegate.swift new file mode 100644 index 0000000..67ab1d9 --- /dev/null +++ b/end-user-api-demo/Delegates/SceneDelegate.swift @@ -0,0 +1,56 @@ +// SceneDelegate.swift +// end-user-api-demo + +import UIKit +import OAuthSwift + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { + for urlContext in URLContexts { + print(urlContext.url) + + OAuthSwift.handle(url: urlContext.url) + } + } + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/end-user-api-demo/Extensions.swift b/end-user-api-demo/Extensions.swift new file mode 100644 index 0000000..3ee8761 --- /dev/null +++ b/end-user-api-demo/Extensions.swift @@ -0,0 +1,65 @@ +// Extensions.swift +// end-user-api-demo + +import Foundation +import CommonCrypto + +// PKCE flow string helpers +extension String { + func urlBase64EncodedString() -> String { + return Data(self.utf8) + .base64EncodedString() + .replacingOccurrences(of: "+", with: "-") + .replacingOccurrences(of: "/", with: "_") + .replacingOccurrences(of: "=", with: "") + } + + func sha256() -> String { + if let stringData = self.data(using: String.Encoding.utf8) { + return hexStringFromData(input: digest(input: stringData as NSData)) + } + return "" + } + + private func digest(input : NSData) -> NSData { + let digestLength = Int(CC_SHA256_DIGEST_LENGTH) + var hash = [UInt8](repeating: 0, count: digestLength) + CC_SHA256(input.bytes, UInt32(input.length), &hash) + return NSData(bytes: hash, length: digestLength) + } + + private func hexStringFromData(input: NSData) -> String { + var bytes = [UInt8](repeating: 0, count: input.length) + input.getBytes(&bytes, length: input.length) + + var hexString = "" + for byte in bytes { + hexString += String(format:"%02x", UInt8(byte)) + } + + return hexString + } +} + +// Param helpers +extension Dictionary { + func percentEncoded() -> Data? { + return map { key, value in + let escapedKey = "\(key)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? "" + let escapedValue = "\(value)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? "" + return escapedKey + "=" + escapedValue + } + .joined(separator: "&") + .data(using: .utf8) + } +} +extension CharacterSet { + static let urlQueryValueAllowed: CharacterSet = { + let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4 + let subDelimitersToEncode = "!$&'()*+,;=" + + var allowed = CharacterSet.urlQueryAllowed + allowed.remove(charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)") + return allowed + }() +} diff --git a/end-user-api-demo/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json b/end-user-api-demo/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/end-user-api-demo/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/end-user-api-demo/Resources/Assets.xcassets/Contents.json b/end-user-api-demo/Resources/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/end-user-api-demo/Resources/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/end-user-api-demo/Storyboards/Base.lproj/LaunchScreen.storyboard b/end-user-api-demo/Storyboards/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/end-user-api-demo/Storyboards/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/end-user-api-demo/Storyboards/Base.lproj/Main.storyboard b/end-user-api-demo/Storyboards/Base.lproj/Main.storyboard new file mode 100644 index 0000000..20a0743 --- /dev/null +++ b/end-user-api-demo/Storyboards/Base.lproj/Main.storyboard @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/end-user-api-demo/Types.swift b/end-user-api-demo/Types.swift new file mode 100644 index 0000000..e0c9565 --- /dev/null +++ b/end-user-api-demo/Types.swift @@ -0,0 +1,18 @@ +// Types.swift +// end-user-api-demo + +import Foundation + +struct Forum: Decodable { + var id: Int + var name: String + var welcome_message: String + var prompt: String +} + +struct Idea: Decodable { + var id: Int + var title: String + var text: String? + var voted: Bool? +} diff --git a/end-user-api-demo/UvApi.swift b/end-user-api-demo/UvApi.swift new file mode 100644 index 0000000..2e99488 --- /dev/null +++ b/end-user-api-demo/UvApi.swift @@ -0,0 +1,216 @@ +// UvApi.swift +// end-user-api-demo + +import Foundation +import OAuthSwift + +// =========================== ENVIRONMENT VARIABLES ================================== +// Your UserVoice domain, e.g. "feedback.uservoice.com" +let domainUrl = ProcessInfo.processInfo.environment["domainUrl"] +// An API key created from the Admin console settings (the secret is not needed) +let apiKey = ProcessInfo.processInfo.environment["apiKey"] +// ==================================================================================== + +class UvApi { + static var oauthSwift: OAuth2Swift? + static var authToken: String = "" + static var apiUrl: String = "https://\(domainUrl!)/api/end_users" + + // + // POST and DELETE requests are authorized with OAuthSwift + // + + static func postVote(forumId: Int, ideaId: Int, onSuccess: @escaping (_ data: Any) -> Void) { + let method = OAuthSwiftHTTPRequest.Method.POST + let route = "/forums/\(forumId)/ideas/\(ideaId)/vote" + + oauthSwift?.startAuthorizedRequest( + "\(apiUrl)\(route)", + method: method, + parameters: [:] + ) { result in + switch result { + case .success(let response): + print("success: POST \(route)") + let decoder = JSONDecoder() + let dataResult = try! decoder.decode(Idea.self, from: response.data) + onSuccess(dataResult) + case .failure: + print("failure: POST \(route)") + } + } + } + + static func deleteVote(forumId: Int, ideaId: Int, onSuccess: @escaping (_ data: Any) -> Void) { + let method = OAuthSwiftHTTPRequest.Method.DELETE + let route = "/forums/\(forumId)/ideas/\(ideaId)/vote" + + oauthSwift?.startAuthorizedRequest( + "\(apiUrl)\(route)", + method: method, + parameters: [:] + ) { result in + switch result { + case .success(let response): + print("success: DELETE \(route)") + let decoder = JSONDecoder() + let dataResult = try! decoder.decode(Idea.self, from: response.data) + onSuccess(dataResult) + case .failure: + print("failure: DELETE \(route)") + } + } + } + + static func postIdea(title: String, forumId: Int, onSuccess: @escaping (_ data: Any) -> Void) { + let method = OAuthSwiftHTTPRequest.Method.POST + let route = "/forums/\(forumId)/ideas" + let params: [String: [String: Any]] = [ + "suggestion": [ + "title": title + ] + ] + + oauthSwift?.startAuthorizedRequest( + "\(apiUrl)\(route)", + method: method, + parameters: params, + headers: [ + "Content-Type": "application/json" + ] + ) { result in + switch result { + case .success(let response): + print("success: POST \(route)") + let decoder = JSONDecoder() + let dataResult = try! decoder.decode(Idea.self, from: response.data) + onSuccess(dataResult) + case .failure: + print("failure: POST \(route)") + } + } + } + + // + // GET requests are made without OAuthSwift, but include a token if signed in + // + + static func getIdea(ideaId: Int, onSuccess: @escaping (_ data: Any) -> Void) { + // method: GET + let route = "/ideas/\(ideaId)" + + UvApi.getRequest(route: route) { (response, data) in + let decoder = JSONDecoder() + let dataResult = try! decoder.decode(Idea.self, from: data as! Data) + onSuccess(dataResult) + } + } + + static func getForumIdeas(forumId: Int, onSuccess: @escaping (_ data: Any) -> Void) { + // method: GET + let route = "/forums/\(forumId)/ideas" + + UvApi.getRequest(route: route) { (response, data) in + let decoder = JSONDecoder() + let dataResult = try! decoder.decode([Idea].self, from: data as! Data) + onSuccess(dataResult) + } + } + + static func getForums(onSuccess: @escaping (_ data: Any) -> Void) { + // method: GET + let route = "/forums" + + UvApi.getRequest(route: route) { (response, data) in + let decoder = JSONDecoder() + let dataResult = try! decoder.decode([Forum].self, from: data as! Data) + onSuccess(dataResult) + } + } + + // + // Authentication + // + + static func isSignedIn() -> Bool { + return authToken != "" + } + + static func signIn(vc: UIViewController, onSuccess: @escaping () -> Void) { + if (isSignedIn()) { + print("Already signed in") + return + } + print("Signing in...") + + oauthSwift = OAuth2Swift( + consumerKey: apiKey!, + consumerSecret: "", + authorizeUrl: "https://\(domainUrl!)/api/v2/oauth/auth", + accessTokenUrl: "https://\(domainUrl!)/api/v2/oauth/token", + responseType: "code" + ) + + // Open the UserVoice login page in a browser window: + oauthSwift!.authorizeURLHandler = SafariURLHandler(viewController: vc, oauthSwift: oauthSwift!) + + // PKCE verification (optional but recommended): + // https://tools.ietf.org/html/rfc7636 + let decodedVerifier = "uv-demo-app" + let codeVerifier = decodedVerifier.urlBase64EncodedString() + let codeChallenge = codeVerifier.sha256().urlBase64EncodedString() + + guard let redirectUri = URL(string: "com.uv.Demo:/oauth2Callback") else { return } + + // When requesting an access token, UserVoice returns a redirect to a login page + // which OAuthSwift renders in a browser window. Once the user successfully + // authenticates, UserVoice redirects back to the URL specified when creating the + // API key ("com.uv.Demo:/oauth2Callback"). + oauthSwift!.authorize( + withCallbackURL: redirectUri, + scope: "scope", + state: "state", + codeChallenge: codeChallenge, + codeChallengeMethod: "S256", + codeVerifier: codeVerifier + ) { result in + switch result { + case .success(let (credential, _, _)): + print("Authorize success") + // This token should be set in the Authorization header of every request. + authToken = credential.oauthToken + onSuccess() + case .failure(let error): + print("Authorize failure") + print(error.localizedDescription) + } + } + } + + // + // Helpers + // + + static func getRequest(route: String, params: Data? = nil, onSuccess: @escaping (_ response: Any, _ data: Any) -> Void) { + let request = NSMutableURLRequest(url: URL(string: apiUrl + route)!); + request.httpMethod = "GET" + request.httpBody = params + if isSignedIn() { + request.setValue("Bearer \(authToken)", forHTTPHeaderField: "Authorization") + } + let task = URLSession.shared.dataTask(with: request as URLRequest) { + data, response, error in + + if error != nil { + print("failure: GET \(route)") + print(error!) + return + } + + print("success: GET \(route)") + onSuccess(response!, data!) + } + task.resume() + } + +} diff --git a/end-user-api-demo/ViewControllers/ForumVC.swift b/end-user-api-demo/ViewControllers/ForumVC.swift new file mode 100644 index 0000000..46fa962 --- /dev/null +++ b/end-user-api-demo/ViewControllers/ForumVC.swift @@ -0,0 +1,88 @@ +// ForumVC.swift +// end-user-api-demo + +import UIKit + +var currentForum: Forum? +class ForumVC: UIViewController, UITableViewDelegate, UITableViewDataSource { + let cellReuseIdentifier = "cell" + @IBOutlet var tableView: UITableView! + @IBOutlet var newIdeaTextField: UITextField! + @IBOutlet var newIdeaSubmit: UIButton! + @IBOutlet var navBar: UINavigationItem! + + var ideas: [Idea] = [] + + func refresh() { + UvApi.getForumIdeas(forumId: currentForum!.id) { data in + self.ideas = data as! Array + DispatchQueue.main.async { + self.tableView.reloadData() + self.newIdeaTextField.text = "" + } + } + } + + @IBAction func onSubmit(_ sender: UIButton) { + if newIdeaTextField.text?.count == 0 { + return + } + + if !UvApi.isSignedIn() { + UvApi.signIn(vc: self) { + self.onSubmit(sender) + } + return + } + + UvApi.postIdea( + title: newIdeaTextField.text!, + forumId: currentForum!.id + ) { result in + self.refresh() + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + newIdeaTextField.placeholder = currentForum!.prompt + navBar.title = currentForum?.name + + if tableView == nil { + tableView = UITableView() + } + + tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) + + // This view controller itself will provide the delegate methods and row data for the table view. + tableView.delegate = self + tableView.dataSource = self + + refresh() + } + + // Number of rows in table view + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.ideas.count + } + + // Create a cell for each table view row + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + // Create a new cell if needed or reuse an old one + let cell:UITableViewCell = (self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as UITableViewCell?)! + + // Set the text from the data model + cell.textLabel?.text = self.ideas[indexPath.row].title + + return cell + } + + // Method to run when table view cell is tapped + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + currentIdea = ideas[indexPath.row] + self.performSegue(withIdentifier: "ShowIdeaDetailFromForum", sender: self) + } + +} diff --git a/end-user-api-demo/ViewControllers/HomeVC.swift b/end-user-api-demo/ViewControllers/HomeVC.swift new file mode 100644 index 0000000..9a9b677 --- /dev/null +++ b/end-user-api-demo/ViewControllers/HomeVC.swift @@ -0,0 +1,53 @@ +// HomeVC.swift +// end-user-api-demo + +import UIKit + +class HomeVC: UIViewController, UITableViewDelegate, UITableViewDataSource { + let cellReuseIdentifier = "cell" + @IBOutlet var tableView: UITableView! + + var forums: [Forum] = [] + + override func viewDidLoad() { + super.viewDidLoad() + + // Register the table view cell class and its reuse id + self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) + + // This view controller itself will provide the delegate methods and row data for the table view. + tableView.delegate = self + tableView.dataSource = self + + UvApi.getForums() { data in + self.forums = data as! Array + DispatchQueue.main.async { + self.tableView.reloadData() + } + } + } + + // Number of rows in table view + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.forums.count + } + + // Create a cell for each table view row + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + // Create a new cell if needed or reuse an old one + let cell:UITableViewCell = (self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as UITableViewCell?)! + + // Set the text from the data model + cell.textLabel?.text = self.forums[indexPath.row].name + + return cell + } + + // Method to run when table view cell is tapped + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + currentForum = forums[indexPath.row] + self.performSegue(withIdentifier: "ShowForumFromHome", sender: self) + } + +} diff --git a/end-user-api-demo/ViewControllers/IdeaDetailVC.swift b/end-user-api-demo/ViewControllers/IdeaDetailVC.swift new file mode 100644 index 0000000..49afc93 --- /dev/null +++ b/end-user-api-demo/ViewControllers/IdeaDetailVC.swift @@ -0,0 +1,55 @@ +// IdeaDetailVC.swift +// end-user-api-demo + +import UIKit + +var currentIdea: Idea? +class IdeaDetailVC: UIViewController { + @IBOutlet var titleLabel: UILabel! + @IBOutlet var textLabel: UILabel! + @IBOutlet var voteButton: UIButton! + + var voted: Bool? + + @IBAction func onVotePress(_ sender: Any) { + if !UvApi.isSignedIn() { + UvApi.signIn(vc: self) { + self.onVotePress(sender) + } + return + } + + if (voted ?? false) { + UvApi.deleteVote(forumId: currentForum!.id, ideaId: currentIdea!.id) { idea in + currentIdea = idea as? Idea + } + } else { + UvApi.postVote(forumId: currentForum!.id, ideaId: currentIdea!.id) { idea in + currentIdea = idea as? Idea + self.updateData() + } + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + self.voteButton.setTitle("Vote", for: UIControl.State.normal) + self.voteButton.setTitle("Voted", for: UIControl.State.selected) + + UvApi.getIdea(ideaId: currentIdea!.id) { result in + currentIdea = result as? Idea + self.updateData() + } + } + + func updateData() { + DispatchQueue.main.async { + self.titleLabel.text = currentIdea?.title + self.textLabel.text = currentIdea?.text + self.voted = currentIdea?.voted ?? false + self.voteButton.isSelected = self.voted ?? false + } + } + +}