From 6fccb70f0d417f2cbcafd8dad1537913999d1c0f Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 24 Apr 2019 08:50:00 -0700 Subject: [PATCH] Add caching interceptor example --- .../project.pbxproj | 421 ++++++++++++++++++ .../InterceptorSample/AppDelegate.h | 25 ++ .../InterceptorSample/AppDelegate.m | 5 + .../AppIcon.appiconset/Contents.json | 98 ++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 ++ .../Base.lproj/Main.storyboard | 38 ++ .../InterceptorSample/CacheInterceptor.h | 90 ++++ .../InterceptorSample/CacheInterceptor.m | 303 +++++++++++++ .../InterceptorSample/Info.plist | 45 ++ .../InterceptorSample/ViewController.h | 25 ++ .../InterceptorSample/ViewController.m | 86 ++++ .../InterceptorSample/main.m | 26 ++ .../examples/InterceptorSample/Podfile | 31 ++ 14 files changed, 1224 insertions(+) create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample.xcodeproj/project.pbxproj create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.h create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.m create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/Contents.json create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/LaunchScreen.storyboard create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/Main.storyboard create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.h create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.m create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/Info.plist create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.h create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.m create mode 100644 src/objective-c/examples/InterceptorSample/InterceptorSample/main.m create mode 100644 src/objective-c/examples/InterceptorSample/Podfile diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample.xcodeproj/project.pbxproj b/src/objective-c/examples/InterceptorSample/InterceptorSample.xcodeproj/project.pbxproj new file mode 100644 index 00000000000..e72ef6edc61 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample.xcodeproj/project.pbxproj @@ -0,0 +1,421 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 1C4854A76EEB56F8096DBDEF /* libPods-InterceptorSample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CB7A7A5B91FC976FCF4637AE /* libPods-InterceptorSample.a */; }; + 5EE960FB2266768A0044A74F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE960FA2266768A0044A74F /* AppDelegate.m */; }; + 5EE960FE2266768A0044A74F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE960FD2266768A0044A74F /* ViewController.m */; }; + 5EE961012266768A0044A74F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5EE960FF2266768A0044A74F /* Main.storyboard */; }; + 5EE961032266768C0044A74F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5EE961022266768C0044A74F /* Assets.xcassets */; }; + 5EE961062266768C0044A74F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5EE961042266768C0044A74F /* LaunchScreen.storyboard */; }; + 5EE961092266768C0044A74F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE961082266768C0044A74F /* main.m */; }; + 5EE9611222668CF20044A74F /* CacheInterceptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE9611122668CF20044A74F /* CacheInterceptor.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 09457A264AAE5323BF50B1F8 /* Pods-InterceptorSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InterceptorSample.debug.xcconfig"; path = "Target Support Files/Pods-InterceptorSample/Pods-InterceptorSample.debug.xcconfig"; sourceTree = ""; }; + 5EE960F62266768A0044A74F /* InterceptorSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = InterceptorSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 5EE960FA2266768A0044A74F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 5EE960FC2266768A0044A74F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 5EE960FD2266768A0044A74F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 5EE961002266768A0044A74F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 5EE961022266768C0044A74F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 5EE961052266768C0044A74F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 5EE961072266768C0044A74F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5EE961082266768C0044A74F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 5EE9610F2266774C0044A74F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 5EE9611022668CE20044A74F /* CacheInterceptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CacheInterceptor.h; sourceTree = ""; }; + 5EE9611122668CF20044A74F /* CacheInterceptor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CacheInterceptor.m; sourceTree = ""; }; + A0789280A4035D0F22F96BE6 /* Pods-InterceptorSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InterceptorSample.release.xcconfig"; path = "Target Support Files/Pods-InterceptorSample/Pods-InterceptorSample.release.xcconfig"; sourceTree = ""; }; + CB7A7A5B91FC976FCF4637AE /* libPods-InterceptorSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InterceptorSample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5EE960F32266768A0044A74F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 1C4854A76EEB56F8096DBDEF /* libPods-InterceptorSample.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 5EE960ED2266768A0044A74F = { + isa = PBXGroup; + children = ( + 5EE960F82266768A0044A74F /* InterceptorSample */, + 5EE960F72266768A0044A74F /* Products */, + 9D49DB75F3BEDAFDE7028B51 /* Pods */, + BD7184728351C7DDAFBA5FA2 /* Frameworks */, + ); + sourceTree = ""; + }; + 5EE960F72266768A0044A74F /* Products */ = { + isa = PBXGroup; + children = ( + 5EE960F62266768A0044A74F /* InterceptorSample.app */, + ); + name = Products; + sourceTree = ""; + }; + 5EE960F82266768A0044A74F /* InterceptorSample */ = { + isa = PBXGroup; + children = ( + 5EE960FA2266768A0044A74F /* AppDelegate.m */, + 5EE960FC2266768A0044A74F /* ViewController.h */, + 5EE960FD2266768A0044A74F /* ViewController.m */, + 5EE960FF2266768A0044A74F /* Main.storyboard */, + 5EE961022266768C0044A74F /* Assets.xcassets */, + 5EE961042266768C0044A74F /* LaunchScreen.storyboard */, + 5EE961072266768C0044A74F /* Info.plist */, + 5EE961082266768C0044A74F /* main.m */, + 5EE9610F2266774C0044A74F /* AppDelegate.h */, + 5EE9611022668CE20044A74F /* CacheInterceptor.h */, + 5EE9611122668CF20044A74F /* CacheInterceptor.m */, + ); + path = InterceptorSample; + sourceTree = ""; + }; + 9D49DB75F3BEDAFDE7028B51 /* Pods */ = { + isa = PBXGroup; + children = ( + 09457A264AAE5323BF50B1F8 /* Pods-InterceptorSample.debug.xcconfig */, + A0789280A4035D0F22F96BE6 /* Pods-InterceptorSample.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + BD7184728351C7DDAFBA5FA2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + CB7A7A5B91FC976FCF4637AE /* libPods-InterceptorSample.a */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5EE960F52266768A0044A74F /* InterceptorSample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5EE9610C2266768C0044A74F /* Build configuration list for PBXNativeTarget "InterceptorSample" */; + buildPhases = ( + 7531607F028A04DAAF5E97B5 /* [CP] Check Pods Manifest.lock */, + 5EE960F22266768A0044A74F /* Sources */, + 5EE960F32266768A0044A74F /* Frameworks */, + 5EE960F42266768A0044A74F /* Resources */, + 17700C95BAEBB27F7A3D1B01 /* [CP] Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = InterceptorSample; + productName = InterceptorSample; + productReference = 5EE960F62266768A0044A74F /* InterceptorSample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5EE960EE2266768A0044A74F /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1010; + ORGANIZATIONNAME = gRPC; + TargetAttributes = { + 5EE960F52266768A0044A74F = { + CreatedOnToolsVersion = 10.1; + }; + }; + }; + buildConfigurationList = 5EE960F12266768A0044A74F /* Build configuration list for PBXProject "InterceptorSample" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 5EE960ED2266768A0044A74F; + productRefGroup = 5EE960F72266768A0044A74F /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5EE960F52266768A0044A74F /* InterceptorSample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 5EE960F42266768A0044A74F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5EE961062266768C0044A74F /* LaunchScreen.storyboard in Resources */, + 5EE961032266768C0044A74F /* Assets.xcassets in Resources */, + 5EE961012266768A0044A74F /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 17700C95BAEBB27F7A3D1B01 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-InterceptorSample/Pods-InterceptorSample-resources.sh", + "${PODS_CONFIGURATION_BUILD_DIR}/gRPC/gRPCCertificates.bundle", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + ); + outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/gRPCCertificates.bundle", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-InterceptorSample/Pods-InterceptorSample-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 7531607F028A04DAAF5E97B5 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-InterceptorSample-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; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 5EE960F22266768A0044A74F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5EE9611222668CF20044A74F /* CacheInterceptor.m in Sources */, + 5EE960FE2266768A0044A74F /* ViewController.m in Sources */, + 5EE961092266768C0044A74F /* main.m in Sources */, + 5EE960FB2266768A0044A74F /* AppDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 5EE960FF2266768A0044A74F /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5EE961002266768A0044A74F /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 5EE961042266768C0044A74F /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5EE961052266768C0044A74F /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 5EE9610A2266768C0044A74F /* 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; + CODE_SIGN_IDENTITY = "iPhone Developer"; + 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 = 12.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 5EE9610B2266768C0044A74F /* 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; + CODE_SIGN_IDENTITY = "iPhone Developer"; + 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 = 12.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 5EE9610D2266768C0044A74F /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 09457A264AAE5323BF50B1F8 /* Pods-InterceptorSample.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = InterceptorSample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = io.grpc.InterceptorSample; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 5EE9610E2266768C0044A74F /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = A0789280A4035D0F22F96BE6 /* Pods-InterceptorSample.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = InterceptorSample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = io.grpc.InterceptorSample; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5EE960F12266768A0044A74F /* Build configuration list for PBXProject "InterceptorSample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5EE9610A2266768C0044A74F /* Debug */, + 5EE9610B2266768C0044A74F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5EE9610C2266768C0044A74F /* Build configuration list for PBXNativeTarget "InterceptorSample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5EE9610D2266768C0044A74F /* Debug */, + 5EE9610E2266768C0044A74F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 5EE960EE2266768A0044A74F /* Project object */; +} diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.h b/src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.h new file mode 100644 index 00000000000..c4e433787e6 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.h @@ -0,0 +1,25 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.m b/src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.m new file mode 100644 index 00000000000..1b9f2c85dac --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/AppDelegate.m @@ -0,0 +1,5 @@ +#import "AppDelegate.h" + +@implementation AppDelegate + +@end diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/AppIcon.appiconset/Contents.json b/src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000000..d8db8d65fd7 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/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/src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/Contents.json b/src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/Contents.json new file mode 100644 index 00000000000..da4a164c918 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/LaunchScreen.storyboard b/src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000000..bfa36129419 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/Main.storyboard b/src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/Main.storyboard new file mode 100644 index 00000000000..9310a8e812f --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/Base.lproj/Main.storyboard @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.h b/src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.h new file mode 100644 index 00000000000..a2c9d668c14 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.h @@ -0,0 +1,90 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RequestCacheEntry : NSObject + +@property(readonly, copy, nullable) NSString *path; +@property(readonly, copy, nullable) id message; + +@end + +@interface MutableRequestCacheEntry : RequestCacheEntry + +@property(copy, nullable) NSString *path; +@property(copy, nullable) id message; + +@end + +@interface ResponseCacheEntry : NSObject + +@property(readonly, copy, nullable) NSDate *deadline; + +@property(readonly, copy, nullable) NSDictionary *headers; +@property(readonly, copy, nullable) id message; +@property(readonly, copy, nullable) NSDictionary *trailers; + +@end + +@interface MutableResponseCacheEntry : ResponseCacheEntry + +@property(copy, nullable) NSDate *deadline; + +@property(copy, nullable) NSDictionary *headers; +@property(copy, nullable) id message; +@property(copy, nullable) NSDictionary *trailers; + +@end + +@interface CacheContext : NSObject + +- (nullable instancetype)init; + +- (nullable ResponseCacheEntry *)getCachedResponseForRequest:(RequestCacheEntry *)request; + +- (void)setCachedResponse:(ResponseCacheEntry *)response forRequest:(RequestCacheEntry *)request; + +@end + +@interface CacheInterceptor : GRPCInterceptor + +- (instancetype)init NS_UNAVAILABLE; + ++ (instancetype)new NS_UNAVAILABLE; + +- (nullable instancetype)initWithInterceptorManager:(GRPCInterceptorManager * _Nonnull)intercepterManager + cacheContext:(CacheContext * _Nonnull)cacheContext NS_DESIGNATED_INITIALIZER; + +// implementation of GRPCInterceptorInterface +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions; +- (void)writeData:(id)data; +- (void)finish; + +// implementation of GRPCResponseHandler +- (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata; +- (void)didReceiveData:(id)data; +- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata + error:(nullable NSError *)error; + +@end + +NS_ASSUME_NONNULL_END diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.m b/src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.m new file mode 100644 index 00000000000..fea770af486 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/CacheInterceptor.m @@ -0,0 +1,303 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import "CacheInterceptor.h" + +@implementation RequestCacheEntry { + @protected + NSString *_path; + id _message; +} + +@synthesize path = _path; +@synthesize message = _message; + +- (instancetype)initWithPath:(NSString *)path message:(id)message { + if ((self = [super init])) { + _path = [path copy]; + _message = [message copy]; + } + return self; +} + +- (id)copyWithZone:(NSZone *)zone { + return [[RequestCacheEntry allocWithZone:zone] initWithPath:_path message:_message]; +} + +- (BOOL)isEqual:(id)object { + if ([self class] != [object class]) return NO; + RequestCacheEntry *rhs = (RequestCacheEntry *)object; + return ([_path isEqualToString:rhs.path] && [_message isEqual:rhs.message]); +} + +- (NSUInteger)hash { + return _path.hash ^ _message.hash; +} + +@end + +@implementation MutableRequestCacheEntry + +@dynamic path; +@dynamic message; + +- (void)setPath:(NSString *)path { + _path = [path copy]; +} + +- (void)setMessage:(id)message { + _message = [message copy]; +} + +@end + +@implementation ResponseCacheEntry { + @protected + NSDate *_deadline; + NSDictionary *_headers; + id _message; + NSDictionary *_trailers; +} + +@synthesize deadline = _deadline; +@synthesize headers = _headers; +@synthesize message = _message; +@synthesize trailers = _trailers; + +- (instancetype)initWithDeadline:(NSDate *)deadline + headers:(NSDictionary *)headers + message:(id)message + trailers:(NSDictionary *)trailers { + if (([super init])) { + _deadline = [deadline copy]; + _headers = [[NSDictionary alloc] initWithDictionary:headers copyItems:YES]; + _message = [message copy]; + _trailers = [[NSDictionary alloc] initWithDictionary:trailers copyItems:YES]; + } + return self; +} + +- (id)copyWithZone:(NSZone *)zone { + return [[ResponseCacheEntry allocWithZone:zone] initWithDeadline:_deadline + headers:_headers + message:_message + trailers:_trailers]; +} + +@end + +@implementation MutableResponseCacheEntry + +@dynamic deadline; +@dynamic headers; +@dynamic message; +@dynamic trailers; + +- (void)setDeadline:(NSDate *)deadline { + _deadline = [deadline copy]; +} + +- (void)setHeaders:(NSDictionary *)headers { + _headers = [[NSDictionary alloc] initWithDictionary:headers copyItems:YES]; +} + +- (void)setMessage:(id)message { + _message = [message copy]; +} + +- (void)setTrailers:(NSDictionary *)trailers { + _trailers = [[NSDictionary alloc] initWithDictionary:trailers copyItems:YES]; +} + +@end + +@implementation CacheContext { + NSCache *_cache; +} + +- (instancetype)init { + if ((self = [super init])) { + _cache = [[NSCache alloc] init]; + } + return self; +} + +- (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { + return [[CacheInterceptor alloc] initWithInterceptorManager:interceptorManager + cacheContext:self]; +} + +- (ResponseCacheEntry *)getCachedResponseForRequest:(RequestCacheEntry *)request { + ResponseCacheEntry *response = nil; + @synchronized (self) { + response = [_cache objectForKey:request]; + } + return response; +} + +- (void)setCachedResponse:(ResponseCacheEntry *)response + forRequest:(RequestCacheEntry *)request { + @synchronized (self) { + [_cache setObject:response forKey:request]; + } +} + +@end + +@implementation CacheInterceptor { + GRPCInterceptorManager *_manager; + CacheContext *_context; + dispatch_queue_t _dispatchQueue; + + BOOL _cacheable; + BOOL _messageSeen; + GRPCCallOptions *_callOptions; + GRPCRequestOptions *_requestOptions; + id _requestMessage; + MutableRequestCacheEntry *_request; + MutableResponseCacheEntry *_response; +} + +- (dispatch_queue_t)requestDispatchQueue { + return _dispatchQueue; +} + +- (dispatch_queue_t)dispatchQueue { + return _dispatchQueue; +} + +- (instancetype)initWithInterceptorManager:(GRPCInterceptorManager * _Nonnull)intercepterManager + cacheContext:(CacheContext * _Nonnull)cacheContext { + if ((self = [super initWithInterceptorManager:intercepterManager + requestDispatchQueue:dispatch_get_main_queue() + responseDispatchQueue:dispatch_get_main_queue()])) { + _manager = intercepterManager; + _context = cacheContext; + _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); + + _cacheable = YES; + _messageSeen = NO; + _request = nil; + _response = nil; + } + return self; +} + +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions { + NSLog(@"start"); + if (requestOptions.safety != GRPCCallSafetyCacheableRequest) { + NSLog(@"no cache"); + _cacheable = NO; + [_manager startNextInterceptorWithRequest:requestOptions callOptions:callOptions]; + } else { + _requestOptions = [requestOptions copy]; + _callOptions = [callOptions copy]; + } +} + +- (void)writeData:(id)data { + NSLog(@"writeData"); + if (!_cacheable) { + [_manager writeNextInterceptorWithData:data]; + } else { + NSAssert(!_messageSeen, @"CacheInterceptor does not support streaming call"); + if (_messageSeen) { + NSLog(@"CacheInterceptor does not support streaming call"); + } + _messageSeen = YES; + _requestMessage = [data copy]; + } +} + +- (void)finish { + NSLog(@"finish"); + if (!_cacheable) { + [_manager finishNextInterceptor]; + } else { + _request = [[MutableRequestCacheEntry alloc] init]; + _request.path = _requestOptions.path; + _request.message = [_requestMessage copy]; + _response = [[_context getCachedResponseForRequest:_request] copy]; + NSLog(@"Read cache for %@", _request); + if (!_response) { + [_manager startNextInterceptorWithRequest:_requestOptions + callOptions:_callOptions]; + [_manager writeNextInterceptorWithData:_requestMessage]; + [_manager finishNextInterceptor]; + } else { + [_manager forwardPreviousInterceptorWithInitialMetadata:_response.headers]; + [_manager forwardPreviousIntercetporWithData:_response.message]; + [_manager forwardPreviousInterceptorCloseWithTrailingMetadata:_response.trailers error:nil]; + [_manager shutDown]; + } + } +} + +- (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata { + NSLog(@"initialMetadata"); + if (_cacheable) { + NSDate *deadline = nil; + for (NSString *key in initialMetadata) { + if ([key.lowercaseString isEqualToString:@"cache-control"]) { + NSArray *cacheControls = [initialMetadata[key] componentsSeparatedByString:@","]; + for (NSString *option in cacheControls) { + NSString *trimmedOption = [option stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]]; + if ([trimmedOption.lowercaseString isEqualToString:@"no-cache"] || + [trimmedOption.lowercaseString isEqualToString:@"no-store"] || + [trimmedOption.lowercaseString isEqualToString:@"no-transform"]) { + _cacheable = NO; + break; + } else if ([trimmedOption.lowercaseString hasPrefix:@"max-age="]) { + NSArray *components = [trimmedOption componentsSeparatedByString:@"="]; + if (components.count == 2) { + NSUInteger maxAge = components[1].intValue; + deadline = [NSDate dateWithTimeIntervalSinceNow:maxAge]; + } + } + } + } + } + if (_cacheable) { + _response = [[MutableResponseCacheEntry alloc] init]; + _response.headers = [initialMetadata copy]; + _response.deadline = deadline; + } + } + [_manager forwardPreviousInterceptorWithInitialMetadata:initialMetadata]; +} + +- (void)didReceiveData:(id)data { + NSLog(@"receiveData"); + if (_cacheable) { + _response.message = [data copy]; + } + [_manager forwardPreviousIntercetporWithData:data]; +} + +- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { + NSLog(@"close"); + if (error == nil && _cacheable) { + _response.trailers = [trailingMetadata copy]; + [_context setCachedResponse:_response forRequest:_request]; + NSLog(@"Write cache for %@", _request); + } + [_manager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata error:error]; + [_manager shutDown]; +} + +@end diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/Info.plist b/src/objective-c/examples/InterceptorSample/InterceptorSample/Info.plist new file mode 100644 index 00000000000..16be3b68112 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.h b/src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.h new file mode 100644 index 00000000000..79de577af81 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.h @@ -0,0 +1,25 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.m b/src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.m new file mode 100644 index 00000000000..79e53313e55 --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/ViewController.m @@ -0,0 +1,86 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import "ViewController.h" + +#import +#import +#import + +#import "CacheInterceptor.h" + +static NSString *const kPackage = @"grpc.testing"; +static NSString *const kService = @"TestService"; + +@interface ViewController () + +@end + +@implementation ViewController { + GRPCCallOptions *_options; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + + GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; + + id factory = [[CacheContext alloc] init]; + options.interceptorFactories = @[ factory ]; + _options = options; +} + +- (IBAction)tapCall:(id)sender { + GRPCProtoMethod *kUnaryCallMethod = + [[GRPCProtoMethod alloc] initWithPackage:kPackage service:kService method:@"UnaryCall"]; + + GRPCRequestOptions *requestOptions = + [[GRPCRequestOptions alloc] initWithHost:@"grpc-test.sandbox.googleapis.com" + path:kUnaryCallMethod.HTTPPath + safety:GRPCCallSafetyCacheableRequest]; + + GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions + responseHandler:self + callOptions:_options]; + + RMTSimpleRequest *request = [RMTSimpleRequest message]; + request.responseSize = 100; + + [call start]; + [call writeData:[request data]]; + [call finish]; + +} + +- (dispatch_queue_t)dispatchQueue { + return dispatch_get_main_queue(); +} + +- (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata { + NSLog(@"Header: %@", initialMetadata); +} + +- (void)didReceiveData:(id)data { + NSLog(@"Message: %@", data); +} + +- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { + NSLog(@"Trailer: %@\nError: %@", trailingMetadata, error); +} + +@end diff --git a/src/objective-c/examples/InterceptorSample/InterceptorSample/main.m b/src/objective-c/examples/InterceptorSample/InterceptorSample/main.m new file mode 100644 index 00000000000..62a9f8e6efb --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/InterceptorSample/main.m @@ -0,0 +1,26 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/src/objective-c/examples/InterceptorSample/Podfile b/src/objective-c/examples/InterceptorSample/Podfile new file mode 100644 index 00000000000..b20813d32aa --- /dev/null +++ b/src/objective-c/examples/InterceptorSample/Podfile @@ -0,0 +1,31 @@ +platform :ios, '8.0' + +install! 'cocoapods', :deterministic_uuids => false + +ROOT_DIR = '../../../..' + +target 'InterceptorSample' do + pod 'gRPC-ProtoRPC', :path => ROOT_DIR + pod 'gRPC', :path => ROOT_DIR + pod 'gRPC-Core', :path => ROOT_DIR + pod 'gRPC-RxLibrary', :path => ROOT_DIR + pod 'RemoteTest', :path => "../RemoteTestClient" + pod '!ProtoCompiler-gRPCPlugin', :path => "#{ROOT_DIR}/src/objective-c" +end + +pre_install do |installer| + grpc_core_spec = installer.pod_targets.find{|t| t.name.start_with?('gRPC-Core')}.root_spec + + src_root = "$(PODS_TARGET_SRCROOT)" + grpc_core_spec.pod_target_xcconfig = { + 'GRPC_SRC_ROOT' => src_root, + 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(GRPC_SRC_ROOT)/include"', + 'USER_HEADER_SEARCH_PATHS' => '"$(GRPC_SRC_ROOT)"', + # If we don't set these two settings, `include/grpc/support/time.h` and + # `src/core/lib/gpr/string.h` shadow the system `` and ``, breaking the + # build. + 'USE_HEADERMAP' => 'NO', + 'ALWAYS_SEARCH_USER_PATHS' => 'NO', + } +end +