Permalink
Browse files

添加了对新浪sso的支持

  • Loading branch information...
1 parent ec10230 commit 8c1df884b6c2f7b929fec14129f903a7b5d3e95d @qdvictory committed Jul 26, 2013
View
@@ -1,20 +1,53 @@
-1.CHShareManager.m中修改配置信息
+新添加了对新浪SSO支持
+
+
+配置步骤
+1.Info.plist添加URL Schemes,schemes为wb+sinapp key的形式
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <dict>
+ <key>CFBundleTypeRole</key>
+ <string>Editor</string>
+ <key>CFBundleURLName</key>
+ <string>minroad.com</string>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>wb2396343608</string>
+ </array>
+ </dict>
+ </plist>
+
+2.在`- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url`中添加回调
+ #import "CHShareManager.h"
+
+ - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
+ {
+ if ([[url scheme] isEqualToString:[NSString stringWithFormat:@"wb%@",kWBAppkey]])
+ {
+ [[CHShareManager mainManager] handleOpenURL:url];
+ }
+ return YES;
+ }
+
+3.CHShareManager.h中修改配置信息
#define kWBAppkey @"xxxx"
#define kWBSecret @"xxx"
#define kQQAppkey @"xxx"
#define kQQSecret @"" //optional
-2.修改qq回调地址
+4.修改qq回调地址
WBAuthorizeWebView.m
#define kQQCallback @"qq.com"
sina无需修改
-3.添加Security.framework
+5.添加Security.framework
-4.调用查看WBShareKitViewController.m
+6.调用查看WBShareKitViewController.m
- (IBAction)sinaSend:(id)sender {
if (![[CHShareManager mainManager] sinaIsVailed]) {
@@ -36,7 +69,7 @@ sina无需修改
}
-5.新版WBShareKit只是将
+7.新版WBShareKit只是将
[http://qzonestyle.gtimg.cn/qzone/vas/opensns/res/doc/Connect_IOS_SDK__V1.2.zip](http://qzonestyle.gtimg.cn/qzone/vas/opensns/res/doc/Connect_IOS_SDK__V1.2.zip)
[http://code.google.com/p/sinaweibosdkforoauth2/downloads/list](http://code.google.com/p/sinaweibosdkforoauth2/downloads/list)
@@ -46,4 +79,5 @@ sina无需修改
http://www.chlova.com
-http://www.minroad.com
+http://www.minroad.com
+
View
@@ -0,0 +1,20 @@
+//
+// URLParser.h
+// isoccer
+//
+// Created by Seamus on 1/25/13.
+// Copyright (c) 2013 Chlova. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface URLParser : NSObject {
+ NSArray *variables;
+}
+
+@property (nonatomic, retain) NSArray *variables;
+
+- (id)initWithURLString:(NSString *)url;
+- (NSString *)valueForVariable:(NSString *)varName;
+
+@end
View
@@ -0,0 +1,47 @@
+//
+// URLParser.m
+// isoccer
+//
+// Created by Seamus on 1/25/13.
+// Copyright (c) 2013 Chlova. All rights reserved.
+//
+
+#import "URLParser.h"
+
+@implementation URLParser
+@synthesize variables;
+
+- (id) initWithURLString:(NSString *)url{
+ self = [super init];
+ if (self != nil) {
+ NSString *string = url;
+ NSScanner *scanner = [NSScanner scannerWithString:string];
+ [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?"]];
+ NSString *tempString;
+ NSMutableArray *vars = [NSMutableArray new];
+ [scanner scanUpToString:@"?" intoString:nil]; //ignore the beginning of the string and skip to the vars
+ while ([scanner scanUpToString:@"&" intoString:&tempString]) {
+ [vars addObject:[tempString copy]];
+ }
+ self.variables = vars;
+ [vars release];
+ }
+ return self;
+}
+
+- (NSString *)valueForVariable:(NSString *)varName {
+ for (NSString *var in self.variables) {
+ if ([var length] > [varName length]+1 && [[var substringWithRange:NSMakeRange(0, [varName length]+1)] isEqualToString:[varName stringByAppendingString:@"="]]) {
+ NSString *varValue = [var substringFromIndex:[varName length]+1];
+ return varValue;
+ }
+ }
+ return nil;
+}
+
+- (void) dealloc{
+ self.variables = nil;
+ [super dealloc];
+}
+
+@end
@@ -19,6 +19,7 @@
65DB245013F02B8300B59C2F /* WBShareKit.png in Resources */ = {isa = PBXBuildFile; fileRef = 65DB244F13F02B8300B59C2F /* WBShareKit.png */; };
65EB81A713F17A94000CA36C /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 65EB81A513F17A94000CA36C /* Icon.png */; };
65EB81A813F17A94000CA36C /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 65EB81A613F17A94000CA36C /* Icon@2x.png */; };
+ F11A3F8917A24E6B0088845A /* URLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F11A3F8817A24E6B0088845A /* URLParser.m */; };
F1AFEC1516020B5100BCF466 /* CHShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F1AFEBED16020B5100BCF466 /* CHShareManager.m */; };
F1AFEC1616020B5100BCF466 /* GTMBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = F1AFEBF116020B5100BCF466 /* GTMBase64.m */; };
F1AFEC1716020B5100BCF466 /* bg.png in Resources */ = {isa = PBXBuildFile; fileRef = F1AFEBF516020B5100BCF466 /* bg.png */; };
@@ -71,6 +72,8 @@
65DB244F13F02B8300B59C2F /* WBShareKit.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = WBShareKit.png; sourceTree = "<group>"; };
65EB81A513F17A94000CA36C /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
65EB81A613F17A94000CA36C /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = "<group>"; };
+ F11A3F8717A24E6B0088845A /* URLParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = URLParser.h; sourceTree = "<group>"; };
+ F11A3F8817A24E6B0088845A /* URLParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = URLParser.m; sourceTree = "<group>"; };
F1AFEBEC16020B5100BCF466 /* CHShareManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHShareManager.h; sourceTree = "<group>"; };
F1AFEBED16020B5100BCF466 /* CHShareManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHShareManager.m; sourceTree = "<group>"; };
F1AFEBF016020B5100BCF466 /* GTMBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMBase64.h; sourceTree = "<group>"; };
@@ -143,6 +146,8 @@
65DB23EE13F0106900B59C2F = {
isa = PBXGroup;
children = (
+ F11A3F8717A24E6B0088845A /* URLParser.h */,
+ F11A3F8817A24E6B0088845A /* URLParser.m */,
F1AFEC441602192500BCF466 /* Security.framework */,
F1AFEC411602190A00BCF466 /* NSString+URLEncoding.h */,
F1AFEC421602190A00BCF466 /* NSString+URLEncoding.m */,
@@ -393,6 +398,7 @@
F1AFEC3B1602187D00BCF466 /* NSObject+SBJSON.m in Sources */,
F1AFEC3C1602187D00BCF466 /* NSString+SBJSON.m in Sources */,
F1AFEC3D1602187D00BCF466 /* SBJSON.m in Sources */,
+ F11A3F8917A24E6B0088845A /* URLParser.m in Sources */,
F1AFEC3E1602187D00BCF466 /* SBJsonBase.m in Sources */,
F1AFEC3F1602187D00BCF466 /* SBJsonParser.m in Sources */,
F1AFEC401602187D00BCF466 /* SBJsonWriter.m in Sources */,
@@ -476,6 +482,7 @@
65DB241B13F0106900B59C2F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CODE_SIGN_IDENTITY = "iPhone Developer: Min Ding (CE72H5XSZ9)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "WBShareKit/WBShareKit-Prefix.pch";
GCC_VERSION = "";
@@ -8,6 +8,11 @@
#import <Foundation/Foundation.h>
#import "WBEngine.h"
+#define kWBAppkey @"2396343608"
+#define kWBSecret @"bb5bdc7df7609a13ffdf7201c32de2b0"
+#define kQQAppkey @"100304947"
+#define kQQSecret @""
+#define kSinaSSOUrl @"sinaweibosso://login"
@interface CHShareManager : NSObject<WBEngineDelegate>
{
@@ -20,6 +25,7 @@
}
+(CHShareManager *)mainManager;
+- (void)handleOpenURL:(NSURL *)_url;
- (BOOL)sinaIsVailed;
- (BOOL)qqIsVailed;
//- (void)getProfile:(NSString *)_type vc:(UIViewController *)_vc;
@@ -7,10 +7,7 @@
//
#import "CHShareManager.h"
-#define kWBAppkey @"2396343608"
-#define kWBSecret @"bb5bdc7df7609a13ffdf7201c32de2b0"
-#define kQQAppkey @"100304947"
-#define kQQSecret @""
+#import "URLParser.h"
@implementation CHShareManager
@@ -77,6 +74,8 @@ - (BOOL)qqIsVailed
- (void)showLoginOnViewController:(UIViewController *)_vc type:(NSString *)_type finish:(SEL)_success failed:(SEL)_failed
{
+
+
[vc release];
vc = nil;
vc = [_vc retain];
@@ -87,13 +86,23 @@ - (void)showLoginOnViewController:(UIViewController *)_vc type:(NSString *)_type
WBEngine *e = nil;
if ([_type isEqualToString:@"sina"]) {
e = sinaEngine;
+// e.redirectURI = @"oauth://minroad.com"
}
else if ([_type isEqualToString:@"qq"])
{
e = qqEngine;
}
// [e setRootViewController:vc];
+
+ if ([_type isEqualToString:@"sina"]) {
+ if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:kSinaSSOUrl]]) {
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?client_id=%@&redirect_uri=%@&callback_uri=%@",kSinaSSOUrl,kWBAppkey,@"http://",[NSString stringWithFormat:@"wb%@://minroad.com",kWBAppkey]]];
+ [[UIApplication sharedApplication] openURL:url];
+ return;
+ }
+ }
+
[e logIn];
}
@@ -140,6 +149,21 @@ - (void)sendWeibo:(NSString *)_status image:(UIImage *)_img type:(NSString *)_ty
}
+#pragma mark -
+- (void)handleOpenURL:(NSURL *)_url
+{
+ NSString *str = [NSString stringWithFormat:@"%@",_url];
+
+ if ([str rangeOfString:@"user_cancelled"].location != NSNotFound) {
+ [sinaEngine authorize:nil didFailWithError:nil];
+ }
+ else
+ {
+ URLParser *parser = [[[URLParser alloc] initWithURLString:str] autorelease];
+ [sinaEngine authorize:nil didSucceedWithAccessToken:[parser valueForVariable:@"access_token"] userID:[parser valueForVariable:@"uid"] expiresIn:[[parser valueForVariable:@"expires_in"] intValue]];
+ }
+}
+
#pragma mark - wbengine
- (void)engineAlreadyLoggedIn:(WBEngine *)engine
{
@@ -168,6 +192,7 @@ - (void)engine:(WBEngine *)engine didFailToLogInWithError:(NSError *)error
vc = nil;
}
+
- (void)engineDidLogOut:(WBEngine *)engine
{
@@ -6,14 +6,17 @@
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
- <key>CFBundleDocumentTypes</key>
- <array/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
+ <key>CFBundleIconFiles</key>
+ <array>
+ <string>Icon@2x.png</string>
+ <string>Icon.png</string>
+ </array>
<key>CFBundleIdentifier</key>
- <string>com.minroad.WBShareKit.${PRODUCT_NAME:rfc1034identifier}</string>
+ <string>com.gaowei.ialert</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
@@ -36,31 +39,32 @@
<string>oauth</string>
</array>
</dict>
+ <dict>
+ <key>CFBundleTypeRole</key>
+ <string>Editor</string>
+ <key>CFBundleURLName</key>
+ <string>minroad.com</string>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>wb2396343608</string>
+ </array>
+ </dict>
</array>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
- <key>UIPrerenderedIcon</key>
- <true/>
<key>UIApplicationExitsOnSuspend</key>
<false/>
+ <key>UIPrerenderedIcon</key>
+ <true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
- <key>UTExportedTypeDeclarations</key>
- <array/>
- <key>UTImportedTypeDeclarations</key>
- <array/>
- <key>CFBundleIconFiles</key>
- <array>
- <string>Icon@2x.png</string>
- <string>Icon.png</string>
- </array>
</dict>
</plist>
@@ -9,6 +9,7 @@
#import "WBShareKitAppDelegate.h"
#import "WBShareKitViewController.h"
+#import "CHShareManager.h"
@implementation WBShareKitAppDelegate
@@ -17,11 +18,12 @@ @implementation WBShareKitAppDelegate
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
-// NSLog(@"获得已授权的key:%@",url);
-
-// [[WBShareKit mainShare] handleOpenURL:url];
-
+ NSLog(@"获得已授权的key:%@",url);
+ if ([[url scheme] isEqualToString:[NSString stringWithFormat:@"wb%@",kWBAppkey]])
+ {
+ [[CHShareManager mainManager] handleOpenURL:url];
+ }
return YES;
}

0 comments on commit 8c1df88

Please sign in to comment.