diff --git a/OpenShareDemo/Open ShareTests/Info.plist b/OpenShareDemo/Open ShareTests/Info.plist new file mode 100644 index 0000000..6c6c23c --- /dev/null +++ b/OpenShareDemo/Open ShareTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/OpenShareDemo/Open ShareTests/Open_ShareTests.m b/OpenShareDemo/Open ShareTests/Open_ShareTests.m new file mode 100644 index 0000000..68ce25f --- /dev/null +++ b/OpenShareDemo/Open ShareTests/Open_ShareTests.m @@ -0,0 +1,39 @@ +// +// Open_ShareTests.m +// Open ShareTests +// +// Created by jinchu darwin on 16/9/20. +// Copyright © 2016年 OpenShare http://openshare.gfzj.us/. All rights reserved. +// + +#import + +@interface Open_ShareTests : XCTestCase + +@end + +@implementation Open_ShareTests + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end diff --git a/OpenShareDemo/openshare.xcodeproj/project.pbxproj b/OpenShareDemo/openshare.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index f033d51..a11ff89 --- a/OpenShareDemo/openshare.xcodeproj/project.pbxproj +++ b/OpenShareDemo/openshare.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ B66BF3B91B0C137E0082F8D6 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B66BF3B81B0C137E0082F8D6 /* ViewController.m */; }; B66BF3BE1B0C137E0082F8D6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B66BF3BD1B0C137E0082F8D6 /* Images.xcassets */; }; B66BF3C11B0C137E0082F8D6 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = B66BF3BF1B0C137E0082F8D6 /* LaunchScreen.xib */; }; - B66BF3CD1B0C137E0082F8D6 /* openshareTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B66BF3CC1B0C137E0082F8D6 /* openshareTests.m */; }; B66BF3DB1B0C14480082F8D6 /* iconfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B66BF3D71B0C14480082F8D6 /* iconfont.ttf */; }; B66BF3DC1B0C14480082F8D6 /* logo.gif in Resources */ = {isa = PBXBuildFile; fileRef = B66BF3D81B0C14480082F8D6 /* logo.gif */; }; B66BF3DD1B0C14480082F8D6 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = B66BF3D91B0C14480082F8D6 /* logo.png */; }; @@ -25,10 +24,12 @@ B66BF3F41B0C1AEB0082F8D6 /* UIControl+Blocks.m in Sources */ = {isa = PBXBuildFile; fileRef = B66BF3F31B0C1AEB0082F8D6 /* UIControl+Blocks.m */; }; B66BF3F81B0C23670082F8D6 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B66BF3F71B0C23670082F8D6 /* Default@2x.png */; }; B6E22B1F1B213B09001930CA /* OpenShare+Alipay.m in Sources */ = {isa = PBXBuildFile; fileRef = B6E22B1E1B213B09001930CA /* OpenShare+Alipay.m */; }; + D02886531D90D22200269A24 /* Open_ShareTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D02886521D90D22200269A24 /* Open_ShareTests.m */; }; + D08B4B131D8FD254004BCB31 /* WebviewAuthHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D08B4B121D8FD254004BCB31 /* WebviewAuthHelper.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - B66BF3C71B0C137E0082F8D6 /* PBXContainerItemProxy */ = { + D02886551D90D22200269A24 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = B66BF3A51B0C137D0082F8D6 /* Project object */; proxyType = 1; @@ -47,7 +48,6 @@ B66BF3B81B0C137E0082F8D6 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; B66BF3BD1B0C137E0082F8D6 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; B66BF3C01B0C137E0082F8D6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; - B66BF3C61B0C137E0082F8D6 /* openshareTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = openshareTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B66BF3CB1B0C137E0082F8D6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B66BF3CC1B0C137E0082F8D6 /* openshareTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = openshareTests.m; sourceTree = ""; }; B66BF3D71B0C14480082F8D6 /* iconfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = iconfont.ttf; sourceTree = ""; }; @@ -70,6 +70,11 @@ B66BF3F71B0C23670082F8D6 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default@2x.png"; path = "Images.xcassets/LaunchImage.launchimage/Default@2x.png"; sourceTree = ""; }; B6E22B1D1B213B09001930CA /* OpenShare+Alipay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "OpenShare+Alipay.h"; sourceTree = ""; }; B6E22B1E1B213B09001930CA /* OpenShare+Alipay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "OpenShare+Alipay.m"; sourceTree = ""; }; + D02886501D90D22200269A24 /* Open ShareTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Open ShareTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + D02886521D90D22200269A24 /* Open_ShareTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Open_ShareTests.m; sourceTree = ""; }; + D02886541D90D22200269A24 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D08B4B111D8FD254004BCB31 /* WebviewAuthHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebviewAuthHelper.h; path = ../openshare/WebviewAuthHelper.h; sourceTree = ""; }; + D08B4B121D8FD254004BCB31 /* WebviewAuthHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WebviewAuthHelper.m; path = ../openshare/WebviewAuthHelper.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -80,7 +85,7 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - B66BF3C31B0C137E0082F8D6 /* Frameworks */ = { + D028864D1D90D22200269A24 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( @@ -95,6 +100,7 @@ children = ( B66BF3AF1B0C137E0082F8D6 /* openshare */, B66BF3C91B0C137E0082F8D6 /* openshareTests */, + D02886511D90D22200269A24 /* Open ShareTests */, B66BF3AE1B0C137E0082F8D6 /* Products */, ); sourceTree = ""; @@ -103,7 +109,7 @@ isa = PBXGroup; children = ( B66BF3AD1B0C137E0082F8D6 /* openshare.app */, - B66BF3C61B0C137E0082F8D6 /* openshareTests.xctest */, + D02886501D90D22200269A24 /* Open ShareTests.xctest */, ); name = Products; sourceTree = ""; @@ -167,6 +173,8 @@ B66BF3E11B0C16290082F8D6 /* OpenShare */ = { isa = PBXGroup; children = ( + D08B4B111D8FD254004BCB31 /* WebviewAuthHelper.h */, + D08B4B121D8FD254004BCB31 /* WebviewAuthHelper.m */, B66BF3E21B0C16290082F8D6 /* OpenShare+QQ.h */, B66BF3E31B0C16290082F8D6 /* OpenShare+QQ.m */, B66BF3E41B0C16290082F8D6 /* OpenShare+Renren.h */, @@ -185,6 +193,15 @@ path = ../../OpenShare; sourceTree = ""; }; + D02886511D90D22200269A24 /* Open ShareTests */ = { + isa = PBXGroup; + children = ( + D02886521D90D22200269A24 /* Open_ShareTests.m */, + D02886541D90D22200269A24 /* Info.plist */, + ); + path = "Open ShareTests"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -205,22 +222,22 @@ productReference = B66BF3AD1B0C137E0082F8D6 /* openshare.app */; productType = "com.apple.product-type.application"; }; - B66BF3C51B0C137E0082F8D6 /* openshareTests */ = { + D028864F1D90D22200269A24 /* Open ShareTests */ = { isa = PBXNativeTarget; - buildConfigurationList = B66BF3D31B0C137E0082F8D6 /* Build configuration list for PBXNativeTarget "openshareTests" */; + buildConfigurationList = D02886571D90D22200269A24 /* Build configuration list for PBXNativeTarget "Open ShareTests" */; buildPhases = ( - B66BF3C21B0C137E0082F8D6 /* Sources */, - B66BF3C31B0C137E0082F8D6 /* Frameworks */, - B66BF3C41B0C137E0082F8D6 /* Resources */, + D028864C1D90D22200269A24 /* Sources */, + D028864D1D90D22200269A24 /* Frameworks */, + D028864E1D90D22200269A24 /* Resources */, ); buildRules = ( ); dependencies = ( - B66BF3C81B0C137E0082F8D6 /* PBXTargetDependency */, + D02886561D90D22200269A24 /* PBXTargetDependency */, ); - name = openshareTests; - productName = openshareTests; - productReference = B66BF3C61B0C137E0082F8D6 /* openshareTests.xctest */; + name = "Open ShareTests"; + productName = "Open ShareTests"; + productReference = D02886501D90D22200269A24 /* Open ShareTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -234,9 +251,13 @@ TargetAttributes = { B66BF3AC1B0C137E0082F8D6 = { CreatedOnToolsVersion = 6.3.1; + DevelopmentTeam = CM2364627B; + ProvisioningStyle = Automatic; }; - B66BF3C51B0C137E0082F8D6 = { - CreatedOnToolsVersion = 6.3.1; + D028864F1D90D22200269A24 = { + CreatedOnToolsVersion = 8.0; + DevelopmentTeam = CM2364627B; + ProvisioningStyle = Automatic; TestTargetID = B66BF3AC1B0C137E0082F8D6; }; }; @@ -255,7 +276,7 @@ projectRoot = ""; targets = ( B66BF3AC1B0C137E0082F8D6 /* openshare */, - B66BF3C51B0C137E0082F8D6 /* openshareTests */, + D028864F1D90D22200269A24 /* Open ShareTests */, ); }; /* End PBXProject section */ @@ -275,7 +296,7 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - B66BF3C41B0C137E0082F8D6 /* Resources */ = { + D028864E1D90D22200269A24 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( @@ -294,6 +315,7 @@ B66BF3B61B0C137E0082F8D6 /* AppDelegate.m in Sources */, B66BF3F41B0C1AEB0082F8D6 /* UIControl+Blocks.m in Sources */, B66BF3F11B0C16290082F8D6 /* OpenShare.m in Sources */, + D08B4B131D8FD254004BCB31 /* WebviewAuthHelper.m in Sources */, B66BF3B31B0C137E0082F8D6 /* main.m in Sources */, B66BF3EF1B0C16290082F8D6 /* OpenShare+Weibo.m in Sources */, B6E22B1F1B213B09001930CA /* OpenShare+Alipay.m in Sources */, @@ -302,21 +324,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - B66BF3C21B0C137E0082F8D6 /* Sources */ = { + D028864C1D90D22200269A24 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - B66BF3CD1B0C137E0082F8D6 /* openshareTests.m in Sources */, + D02886531D90D22200269A24 /* Open_ShareTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - B66BF3C81B0C137E0082F8D6 /* PBXTargetDependency */ = { + D02886561D90D22200269A24 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = B66BF3AC1B0C137E0082F8D6 /* openshare */; - targetProxy = B66BF3C71B0C137E0082F8D6 /* PBXContainerItemProxy */; + targetProxy = D02886551D90D22200269A24 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -419,10 +441,15 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = CM2364627B; INFOPLIST_FILE = openshare/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = top.dawenhing.openshare; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; + PROVISIONING_PROFILE_SPECIFIER = ""; }; name = Debug; }; @@ -431,42 +458,51 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = CM2364627B; INFOPLIST_FILE = openshare/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = top.dawenhing.openshare; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; + PROVISIONING_PROFILE_SPECIFIER = ""; }; name = Release; }; - B66BF3D41B0C137E0082F8D6 /* Debug */ = { + D02886581D90D22200269A24 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = openshareTests/Info.plist; + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = CM2364627B; + ENABLE_TESTABILITY = YES; + INFOPLIST_FILE = "Open ShareTests/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "top.dawenhing.Open-ShareTests"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/openshare.app/openshare"; }; name = Debug; }; - B66BF3D51B0C137E0082F8D6 /* Release */ = { + D02886591D90D22200269A24 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - INFOPLIST_FILE = openshareTests/Info.plist; + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + DEVELOPMENT_TEAM = CM2364627B; + INFOPLIST_FILE = "Open ShareTests/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "top.dawenhing.Open-ShareTests"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/openshare.app/openshare"; }; @@ -493,14 +529,13 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - B66BF3D31B0C137E0082F8D6 /* Build configuration list for PBXNativeTarget "openshareTests" */ = { + D02886571D90D22200269A24 /* Build configuration list for PBXNativeTarget "Open ShareTests" */ = { isa = XCConfigurationList; buildConfigurations = ( - B66BF3D41B0C137E0082F8D6 /* Debug */, - B66BF3D51B0C137E0082F8D6 /* Release */, + D02886581D90D22200269A24 /* Debug */, + D02886591D90D22200269A24 /* Release */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/OpenShareDemo/openshare.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/OpenShareDemo/openshare.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/OpenShareDemo/openshare.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/OpenShareDemo/openshare.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings old mode 100644 new mode 100755 diff --git a/OpenShareDemo/openshare.xcodeproj/xcshareddata/xcschemes/openshare.xcscheme b/OpenShareDemo/openshare.xcodeproj/xcshareddata/xcschemes/openshare.xcscheme old mode 100644 new mode 100755 index 13fbe3c..3590d05 --- a/OpenShareDemo/openshare.xcodeproj/xcshareddata/xcschemes/openshare.xcscheme +++ b/OpenShareDemo/openshare.xcodeproj/xcshareddata/xcschemes/openshare.xcscheme @@ -37,10 +37,10 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -52,6 +52,16 @@ ReferencedContainer = "container:openshare.xcodeproj"> + + + + + + @@ -86,10 +99,10 @@ diff --git a/OpenShareDemo/openshare/AppDelegate.m b/OpenShareDemo/openshare/AppDelegate.m index 9a4874d..02dd6d7 100644 --- a/OpenShareDemo/openshare/AppDelegate.m +++ b/OpenShareDemo/openshare/AppDelegate.m @@ -21,7 +21,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( //第一步:注册key [OpenShare connectQQWithAppId:@"1103194207"]; - [OpenShare connectWeiboWithAppKey:@"402180334"]; + // TODO: 重新申请一个 + [OpenShare connectWeiboWithAppKey:@"1457440153" andAppSecret:@"a5829047ff43ce3f8835ec61e2df338a"]; [OpenShare connectWeixinWithAppId:@"wxd930ea5d5a258f4f"]; [OpenShare connectRenrenWithAppId:@"228525" AndAppKey:@"1dd8cba4215d4d4ab96a49d3058c1d7f"]; [OpenShare connectAlipay];//支付宝参数都是服务器端生成的,这里不需要key. diff --git a/OpenShareDemo/openshare/Images.xcassets/AppIcon.appiconset/Contents.json b/OpenShareDemo/openshare/Images.xcassets/AppIcon.appiconset/Contents.json index eff7289..9da1b19 100644 --- a/OpenShareDemo/openshare/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/OpenShareDemo/openshare/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "size" : "29x29", "idiom" : "iphone", @@ -36,6 +46,16 @@ "filename" : "logo180.png", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -67,6 +87,11 @@ "idiom" : "ipad", "filename" : "logo-152.png", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/OpenShareDemo/openshare/Info.plist b/OpenShareDemo/openshare/Info.plist index 326a8fa..ed04f5b 100644 --- a/OpenShareDemo/openshare/Info.plist +++ b/OpenShareDemo/openshare/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - us.gfzj.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -18,14 +18,146 @@ 1.0 CFBundleSignature ???? + CFBundleURLTypes + + + CFBundleURLName + OpenShare + CFBundleURLSchemes + + openshare + wxd930ea5d5a258f4f + tencent1103194207 + tencent1103194207.content + QQ41C1685F + wb402180334 + wb2593037974 + renrenshare228525 + fb776442542471056 + + + CFBundleVersion 1 + LSApplicationQueriesSchemes + + wechat + weixin + sinaweibohd + sinaweibo + sinaweibosso + weibosdk + weibosdk2.5 + mqqapi + mqq + mqqOpensdkSSoLogin + mqqconnect + mqqopensdkdataline + mqqopensdkgrouptribeshare + mqqopensdkfriend + mqqopensdkapi + mqqopensdkapiV2 + mqqopensdkapiV3 + mqzoneopensdk + wtloginmqq + wtloginmqq2 + mqqwpa + mqzone + mqzonev2 + mqzoneshare + wtloginqzone + mqzonewx + mqzoneopensdkapiV2 + mqzoneopensdkapi19 + mqzoneopensdkapi + mqzoneopensdk + renrenios + renrenapi + renren + renreniphone + yixin + instagram + whatsapp + line + fbapi + fb-messenger-api + fbauth2 + fbshareextension + LSRequiresIPhoneOS + NSAppTransportSecurity + + NSExceptionDomains + + api.weibo.com + + NSIncludesSubdomains + + NSThirdPartyExceptionMinimumTLSVersion + TLSv1.0 + NSThirdPartyExceptionRequiresForwardSecrecy + + + open.weibo.cn + + NSIncludesSubdomains + + NSThirdPartyExceptionMinimumTLSVersion + TLSv1.0 + NSThirdPartyExceptionRequiresForwardSecrecy + + + openshare.gfzj.us + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + NSThirdPartyExceptionMinimumTLSVersion + TLSv1.0 + NSThirdPartyExceptionRequiresForwardSecrecy + + + qq.com + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + NSThirdPartyExceptionMinimumTLSVersion + TLSv1.0 + NSThirdPartyExceptionRequiresForwardSecrecy + + + sina.com.cn + + NSIncludesSubdomains + + NSThirdPartyExceptionMinimumTLSVersion + TLSv1.0 + NSThirdPartyExceptionRequiresForwardSecrecy + + + www.dawenhing.im + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + NSThirdPartyExceptionMinimumTLSVersion + TLSv1.0 + NSThirdPartyExceptionRequiresForwardSecrecy + + + + + UIAppFonts + + iconfont.ttf + UILaunchStoryboardName LaunchScreen - - UIRequiredDeviceCapabilities armv7 @@ -38,104 +170,5 @@ UIInterfaceOrientationPortrait - - - CFBundleURLTypes - - - CFBundleURLName - OpenShare - CFBundleURLSchemes - - -openshare - -wxd930ea5d5a258f4f - -tencent1103194207 -tencent1103194207.content -QQ41C1685F - -wb402180334 - -renrenshare228525 - -fb776442542471056 - - - - - -UIAppFonts - - iconfont.ttf - - - -LSApplicationQueriesSchemes - - - wechat - weixin - - - sinaweibohd - sinaweibo - sinaweibosso - weibosdk - weibosdk2.5 - - - mqqapi - mqq - mqqOpensdkSSoLogin - mqqconnect - mqqopensdkdataline - mqqopensdkgrouptribeshare - mqqopensdkfriend - mqqopensdkapi - mqqopensdkapiV2 - mqqopensdkapiV3 - mqzoneopensdk - wtloginmqq - wtloginmqq2 - mqqwpa - mqzone - mqzonev2 - mqzoneshare - wtloginqzone - mqzonewx - mqzoneopensdkapiV2 - mqzoneopensdkapi19 - mqzoneopensdkapi - mqzoneopensdk - - - renrenios - renrenapi - renren - renreniphone - - - yixin - - - instagram - - - whatsapp - - - line - - - fbapi - fb-messenger-api - fbauth2 - fbshareextension - - - - diff --git a/OpenShareDemo/openshare/ViewController.m b/OpenShareDemo/openshare/ViewController.m index c64dafc..4a913ec 100644 --- a/OpenShareDemo/openshare/ViewController.m +++ b/OpenShareDemo/openshare/ViewController.m @@ -149,7 +149,7 @@ -(UIView*)sinaWeiboView:(CGRect)frame{ UIButton *auth=[self button:@"登录" WithCenter:CGPointMake(frame.size.width/2, 40)]; [ret addSubview:auth]; [auth addEventHandler:^(id sender) { - [OpenShare WeiboAuth:@"all" redirectURI:@"http://openshare.gfzj.us/" Success:^(NSDictionary *message) { + [OpenShare WeiboAuth:@"all" redirectURI:@"www.dawenhing.im" Success:^(NSDictionary *message) { ULog(@"微博登录成功:\n%@",message); } Fail:^(NSDictionary *message, NSError *error) { ULog(@"微博登录失败:\n%@\n%@",message,error); @@ -550,4 +550,4 @@ - (UIImage *)imageWithColor:(UIColor *)color return image; } -@end \ No newline at end of file +@end diff --git a/OpenShareDemo/openshareTests/Info.plist b/OpenShareDemo/openshareTests/Info.plist index 61dad52..ba72822 100644 --- a/OpenShareDemo/openshareTests/Info.plist +++ b/OpenShareDemo/openshareTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - us.gfzj.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/openshare/OpenShare+Weibo.h b/openshare/OpenShare+Weibo.h index 9c4ec9c..36f2d72 100644 --- a/openshare/OpenShare+Weibo.h +++ b/openshare/OpenShare+Weibo.h @@ -15,7 +15,7 @@ * * @param appKey 申请到的appKey */ -+(void)connectWeiboWithAppKey:(NSString *)appKey; ++(void)connectWeiboWithAppKey:(NSString *)appKey andAppSecret:(NSString *)secret; +(BOOL)isWeiboInstalled; /** * 分享到微博,微博只支持三种类型:文本/图片/链接。根据OSMessage自动判定想分享的类型。 diff --git a/openshare/OpenShare+Weibo.m b/openshare/OpenShare+Weibo.m index 612c38a..f3d79da 100644 --- a/openshare/OpenShare+Weibo.m +++ b/openshare/OpenShare+Weibo.m @@ -10,8 +10,8 @@ @implementation OpenShare (Weibo) static NSString *schema=@"Weibo"; -+(void)connectWeiboWithAppKey:(NSString *)appKey{ - [self set:schema Keys:@{@"appKey":appKey}]; ++(void)connectWeiboWithAppKey:(NSString *)appKey andAppSecret:(NSString *)secret { + [self set:schema Keys:@{@"appKey":appKey, @"appSecret": secret}]; } +(BOOL)isWeiboInstalled{ return [self canOpen:@"weibosdk://request"]; @@ -71,29 +71,36 @@ +(void)WeiboAuth:(NSString*)scope redirectURI:(NSString*)redirectURI Success:(au if (![self beginAuth:schema Success:success Fail:fail]) { return; } - NSString *uuid=[[NSUUID UUID] UUIDString]; - NSArray *authData=@[ - @{@"transferObject":[NSKeyedArchiver archivedDataWithRootObject:@{ - @"__class" :@"WBAuthorizeRequest", - @"redirectURI":redirectURI, - @"requestID" :uuid, - @"scope": scope?:@"all" - }]}, - @{@"userInfo":[NSKeyedArchiver archivedDataWithRootObject:@{ - @"mykey":@"as you like", - @"SSO_From" : @"SendMessageToWeiboViewController" - }] - }, - - @{@"app":[NSKeyedArchiver archivedDataWithRootObject:@{ - @"appKey" :[self keyFor:schema][@"appKey"], - @"bundleID" : [self CFBundleIdentifier], - @"name" :[self CFBundleDisplayName] - }] - } - ]; - [UIPasteboard generalPasteboard].items=authData; - [self openURL:[NSString stringWithFormat:@"weibosdk://request?id=%@&sdkversion=003013000",uuid]]; + if ([self isWeiboInstalled]) { + NSString *uuid=[[NSUUID UUID] UUIDString]; + NSArray *authData=@[ + @{@"transferObject":[NSKeyedArchiver archivedDataWithRootObject:@{ + @"__class" :@"WBAuthorizeRequest", + @"redirectURI":redirectURI, + @"requestID" :uuid, + @"scope": scope?:@"all" + }]}, + @{@"userInfo":[NSKeyedArchiver archivedDataWithRootObject:@{ + @"mykey":@"as you like", + @"SSO_From" : @"SendMessageToWeiboViewController" + }] + }, + + @{@"app":[NSKeyedArchiver archivedDataWithRootObject:@{ + @"appKey" :[self keyFor:schema][@"appKey"], + @"bundleID" : [self CFBundleIdentifier], + @"name" :[self CFBundleDisplayName] + }] + } + ]; + [UIPasteboard generalPasteboard].items=authData; + [self openURL:[NSString stringWithFormat:@"weibosdk://request?id=%@&sdkversion=003013000",uuid]]; + } + else { + // Web OAuth + NSString *webOAuth = [NSString stringWithFormat:@"https://open.weibo.cn/oauth2/authorize?client_id=%@&client_secret=%@&response_type=code&redirect_uri=%@&scope=%@", [self keyFor:schema][@"appKey"], [self keyFor:schema][@"appSecret"], redirectURI, scope?:@"all"]; + [self openWebAuth:webOAuth redirectURI:redirectURI]; + } } +(BOOL)Weibo_handleOpenURL{ diff --git a/openshare/OpenShare.h b/openshare/OpenShare.h index d8e211f..9c4cf71 100644 --- a/openshare/OpenShare.h +++ b/openshare/OpenShare.h @@ -8,6 +8,7 @@ #import #import + /** 分享类型,除了news以外,还可能是video/audio/app等。 */ @@ -34,6 +35,8 @@ typedef enum : NSUInteger { @property NSString* mediaDataUrl; @property NSString* fileExt; @property (nonatomic, strong) NSData *file; /// 微信分享gif/文件 + +//@property (nonatomic, strong) UIWebView *authWebview; /** * 判断emptyValueForKeys的value都是空的,notEmptyValueForKeys的value都不是空的。 * @@ -141,6 +144,9 @@ typedef enum : NSUInteger { + (NSData *)dataWithImage:(UIImage *)image; + (NSData *)dataWithImage:(UIImage *)image scale:(CGSize)size; ++ (void)openWebAuth:(NSString *)webAuth redirectURI:(NSString *)redirectURI; ++ (void)finishWebAuthWithResult:(NSDictionary *)info error:(NSError *)error; + @end diff --git a/openshare/OpenShare.m b/openshare/OpenShare.m index 3dfd543..1583a62 100644 --- a/openshare/OpenShare.m +++ b/openshare/OpenShare.m @@ -7,6 +7,8 @@ // #import "OpenShare.h" +#import "WebviewAuthHelper.h" +#import @implementation OpenShare /** @@ -269,6 +271,31 @@ - (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size{ return scaledImage; } ++ (void)openWebAuth:(NSString *)webAuth redirectURI:(NSString *)redirectURI { + NSURL *URL = [NSURL URLWithString:webAuth]; + NSURLRequest *request = [[NSURLRequest alloc] initWithURL:URL]; + WebviewAuthHelper *helper = [[WebviewAuthHelper alloc] init]; + helper.finishRedirectURI = redirectURI; + WKWebView *webview = helper.webview; + [webview loadRequest:request]; + [helper showAuthview]; +} + ++ (void)finishWebAuthWithResult:(NSDictionary *)info error:(NSError *)error{ + if (!error) { + NSLog(@"auth result:%@", info); + if (self.authSuccessCallback) { + self.authSuccessCallback(info); + } + } + else { + NSLog(@"finished with error:%@", error); + if (self.authFailCallback) { + self.authFailCallback(info, error); + } + } +} + @end @implementation OSMessage @@ -296,4 +323,4 @@ -(BOOL)isEmpty:(NSArray*)emptyValueForKeys AndNotEmpty:(NSArray*)notEmptyValueFo } } -@end \ No newline at end of file +@end diff --git a/openshare/WebviewAuthHelper.h b/openshare/WebviewAuthHelper.h new file mode 100644 index 0000000..5eea81e --- /dev/null +++ b/openshare/WebviewAuthHelper.h @@ -0,0 +1,20 @@ +// +// WebviewAuthHelpeer.h +// openshare +// +// Created by dourgulf on 16/9/18. +// + +#import +#import + +@interface WebviewAuthHelper : NSObject + +@property (copy, nonatomic) NSString *finishRedirectURI; +@property (strong, readonly, nonatomic) WKWebView *webview; +@property (strong, readonly, nonatomic) UIActivityIndicatorView *loadingIV; + +- (void)showAuthview; + + +@end diff --git a/openshare/WebviewAuthHelper.m b/openshare/WebviewAuthHelper.m new file mode 100644 index 0000000..f3d39c7 --- /dev/null +++ b/openshare/WebviewAuthHelper.m @@ -0,0 +1,218 @@ +// +// WebviewAuthHelpeer.m +// openshare +// +// Created by dourgulf on 16/9/18. +// + +#import "WebviewAuthHelper.h" +#import "OpenShare.h" + +@interface WebviewAuthHelper() + +@property (strong, nonatomic) UIView *containerView; +@property (strong, nonatomic) WKWebView *webview; +@property (strong, nonatomic) UIActivityIndicatorView *loadingIV; +@property (strong, nonatomic) NSDictionary *loadingParameters; + +@property (strong, nonatomic) id keepInMemory; + +@end + +@implementation WebviewAuthHelper + +- (instancetype)init +{ + self = [super init]; + if (self) { + _containerView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; + UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem]; + closeButton.frame = CGRectMake(8, 20, 80, 36); + closeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + [closeButton setTitle:@"关闭" forState:UIControlStateNormal]; + [closeButton addTarget:self action:@selector(didPressCloseButton) forControlEvents:UIControlEventTouchUpInside]; + [_containerView addSubview:closeButton]; + + CGRect frame = [UIScreen mainScreen].bounds; + frame.origin.y = 25 + 36; + _webview = [[WKWebView alloc] initWithFrame:frame]; + [_containerView addSubview:_webview]; + _webview.navigationDelegate = self; + _loadingIV = [[UIActivityIndicatorView alloc] init]; + _loadingIV.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; + [_webview addSubview:_loadingIV]; + } + return self; +} + +- (void)dealloc +{ +#ifdef DEBUG + NSLog(@"%@ dealloc", NSStringFromClass([self class])); +#endif +} + +- (void)startLoadingIndicator{ + _loadingIV.center = _webview.center; + [_loadingIV startAnimating]; +} + +- (void)stopLoadingIndicator { + [_loadingIV stopAnimating]; +} + +- (void)didPressCloseButton { + NSLog(@"User cancelled"); + [self closeAuthviewWithResult:nil error:[NSError errorWithDomain:@"User Cancelled" code:-1 userInfo:nil]]; +} + +#pragma mark 视图显示生命周期 +- (void)showAuthview { + self.keepInMemory = self; + CGRect frame = _containerView.frame; + frame.origin.y = frame.size.height; + _containerView.frame = frame; + [[UIApplication sharedApplication].keyWindow addSubview:_containerView]; + [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ + CGRect newFrame = frame; + newFrame.origin.y = 0; + _containerView.frame = newFrame; + } completion: nil]; +} + +- (void)closeAuthviewWithResult:(NSDictionary *)info error:(NSError *)err { + CGRect frame = _containerView.frame; + frame.origin.y = frame.size.height; + [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ + _containerView.frame = frame; + } completion:^(BOOL finished) { + [_containerView removeFromSuperview]; + [OpenShare finishWebAuthWithResult:info error:err]; + self.keepInMemory = nil; + }]; +} + +#pragma mark 辅助方法 +- (NSDictionary *)extractParametersOfURI:(NSURL *)URL { + NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:NO]; + NSMutableDictionary *params = [NSMutableDictionary dictionary]; + for (NSURLQueryItem *item in components.queryItems) { + [params setObject:item.value forKey:item.name]; + } + return params; +} + +- (BOOL)isFinishRedirectURI:(NSURL *)URL { + NSString *host = [URL host]; + NSLog(@"isFinishRedirectURI:%@, %@", host, self.finishRedirectURI); + return self.finishRedirectURI.length > 0 && [self.finishRedirectURI containsString:host]; +} + +- (void)postRequestURL:(NSURL *)URL completion:(void(^)(NSDictionary *info, NSError *err))handler { + NSURLSessionConfiguration *configure = [NSURLSessionConfiguration defaultSessionConfiguration]; + NSURLSession *session = [NSURLSession sessionWithConfiguration:configure]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; + request.HTTPMethod = @"POST"; + NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + if (error == nil && data != nil) { + NSError *error; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; + if (!error && [json isKindOfClass:[NSDictionary class]]) { + if (handler) { + handler(json, nil); + } + } + else { + NSString *info = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + NSLog(@"JSON serailzation error:%@, %@", error, info); + } + } + else { + if (handler) { + handler(nil, error); + } + } + }]; + [task resume]; +} + +#pragma mark - WKWebView代理方法 + +// 页面开始加载时调用 +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation { + [self startLoadingIndicator]; +} + +// 收到服务器的跳转请求的时候触发 +- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation { + NSURL *navURL = webView.URL; + if ([self isFinishRedirectURI:navURL]) { + NSDictionary *codeParams = [self extractParametersOfURI:navURL]; + NSString *code = codeParams[@"code"]; + if (code.length > 0) { + [webView stopLoading]; + NSMutableString *userInfoAPI = [NSMutableString stringWithString:@"https://api.weibo.com/oauth2/access_token?"]; + [userInfoAPI appendFormat:@"code=%@", code]; + [userInfoAPI appendFormat:@"&client_id=%@", self.loadingParameters[@"client_id"]]; + [userInfoAPI appendFormat:@"&client_secret=%@", self.loadingParameters[@"client_secret"]]; + [userInfoAPI appendFormat:@"&redirect_uri=%@", self.loadingParameters[@"redirect_uri"]]; + [userInfoAPI appendString:@"&grant_type=authorization_code"]; + NSLog(@"redirect %@", userInfoAPI); + [self postRequestURL:[NSURL URLWithString:userInfoAPI] completion:^(NSDictionary *info, NSError *err) { + NSLog(@"completion info:%@", info); + dispatch_async(dispatch_get_main_queue(), ^{ + // 把字典修正 + NSString *accessToken = info[@"access_token"]? : @""; + NSString *userID = info[@"uid"] ? : @""; + NSDictionary *normalInfo = @{@"accessToken": accessToken, @"userID": userID}; + [self closeAuthviewWithResult:normalInfo error:err]; + }); + }]; + } + else { + [self closeAuthviewWithResult:nil error:nil]; + } + } +} + +// 页面加载完成之后调用 +- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation { + [self stopLoadingIndicator]; + + // 把微博授权的注册按钮屏蔽掉 + if ([webView.URL.host containsString:@"open.weibo.cn"]) { + // 这个OAuth认证好可怕呀, 恶意APP是不是可以随便添加脚本获得用户的账号信息.... + NSString *scriptString = @"document.querySelector('aside.logins').style.display = 'none';"; + [webView evaluateJavaScript:scriptString completionHandler:nil]; + // TODO: 这里可能实现不够严谨 + NSDictionary *params = [self extractParametersOfURI:webView.URL]; + if (params.count > 0) { + self.loadingParameters = params; + } + } +} + +// 页面加载失败时调用 +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error +{ + [self stopLoadingIndicator]; + NSURL *failingURL = [[error userInfo] objectForKey:NSURLErrorFailingURLErrorKey]; + if (![self isFinishRedirectURI:failingURL]) { + [self closeAuthviewWithResult:nil error:error]; + } +} + +- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { + [self stopLoadingIndicator]; + NSURL *failingURL = [[error userInfo] objectForKey:NSURLErrorFailingURLErrorKey]; + if (![self isFinishRedirectURI:failingURL]) { + [self closeAuthviewWithResult:nil error:error]; + } +} + +- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView { + [self stopLoadingIndicator]; + [self closeAuthviewWithResult:nil error:[NSError errorWithDomain:@"Terminated" code:-2 userInfo:nil]]; +} + +@end