Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改善 Demo、增加网页登录 #9

Merged
merged 9 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add wechat login
  • Loading branch information
lzwjava committed Jul 28, 2015
commit d29ee3a855fcd751b9a4e1e370b8bf294b499516
6 changes: 6 additions & 0 deletions LeanCloudSocial/AVSNSWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ @interface AVSNSWebViewController ()

@implementation AVSNSWebViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"账号绑定";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(close)];
}

- (NSDictionary *)extractParamsFromUrl:(NSURL *)url {
NSMutableDictionary *params = [[url av_queryDictionary] mutableCopy];
return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@
5CC504A61B0EF46C004D0CB1 /* AppDelegate.m */,
5CC504A81B0EF46C004D0CB1 /* ViewController.h */,
5CC504A91B0EF46C004D0CB1 /* ViewController.m */,
5CC505C31B146051004D0CB1 /* ResultViewController.h */,
5CC505C41B146051004D0CB1 /* ResultViewController.m */,
5CC504AB1B0EF46C004D0CB1 /* Main.storyboard */,
5CC504AE1B0EF46C004D0CB1 /* Images.xcassets */,
5CC504B01B0EF46C004D0CB1 /* LaunchScreen.xib */,
5CC504A11B0EF46C004D0CB1 /* Supporting Files */,
5CC505C31B146051004D0CB1 /* ResultViewController.h */,
5CC505C41B146051004D0CB1 /* ResultViewController.m */,
);
path = LeanCloudSocialDemo;
sourceTree = "<group>";
Expand Down
12 changes: 6 additions & 6 deletions LeanCloudSocialDemo/LeanCloudSocialDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSString *appKey = @"7dtvdetcfggpalwtf91pdoootc7csxx0vxyi3ayqtbnlklq2";
[AVOSCloud setApplicationId:appId clientKey:appKey];
NSLog(@"setAppId:%@, appKey:%@", appId, appKey);
[AVOSCloud setAllLogsEnabled:YES];
[AVOSCloud setLastModifyEnabled:YES];

[AVOSCloudSNS setupPlatform:AVOSCloudSNSSinaWeibo withAppKey:@"2548122881" andAppSecret:@"ba37a6eb3018590b0d75da733c4998f8" andRedirectURI:@"http://wanpaiapp.com/oauth/callback/sina"];
[AVOSCloudSNS setupPlatform:AVOSCloudSNSQQ withAppKey:@"100512940" andAppSecret:@"afbfdff94b95a2fb8fe58a8e24c4ba5f" andRedirectURI:nil];

[AVOSCloud setVerbosePolicy:kAVVerboseShow];
[AVLogger addLoggerDomain:AVLoggerDomainIM];
[AVLogger addLoggerDomain:AVLoggerDomainCURL];
[AVLogger setLoggerLevelMask:AVLoggerLevelAll];

return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [AVOSCloudSNS handleOpenURL:url];
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
Expand Down
37 changes: 35 additions & 2 deletions LeanCloudSocialDemo/LeanCloudSocialDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EJT-vP-NV4">
<rect key="frame" x="36" y="100" width="528" height="30"/>
<state key="normal" title="新浪微博登录">
<state key="normal" title="微博登录">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
Expand Down Expand Up @@ -47,29 +47,62 @@
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ilD-ZX-Ker">
<rect key="frame" x="36" y="150" width="528" height="30"/>
<state key="normal" title="腾讯 QQ 登录">
<state key="normal" title="QQ 登录">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="qzoneLogin:" destination="x5A-6p-PRh" eventType="touchUpInside" id="tUB-aD-waf"/>
<segue destination="Byc-IT-joB" kind="show" identifier="QQResult" id="fX4-3v-OM4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Hfi-RE-sgf">
<rect key="frame" x="255" y="298" width="90" height="30"/>
<state key="normal" title="微博网页登录">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="weiboLogin2:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="FHi-qH-9Sg"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ErE-Yi-cst">
<rect key="frame" x="255" y="389" width="90" height="30"/>
<state key="normal" title="微信网页登录">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="wechatLogin:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="IXb-gi-QDK"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="B4U-QD-nvc">
<rect key="frame" x="256" y="345" width="88" height="30"/>
<state key="normal" title="QQ 网页登录">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="qzoneLogin2:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="KHe-pg-6zQ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="EJT-vP-NV4" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="1Bn-kH-E9E"/>
<constraint firstItem="ilD-ZX-Ker" firstAttribute="top" secondItem="EJT-vP-NV4" secondAttribute="bottom" constant="20" id="4Aa-HN-Cud"/>
<constraint firstAttribute="trailingMargin" secondItem="EJT-vP-NV4" secondAttribute="trailing" constant="20" id="6uj-1c-6er"/>
<constraint firstAttribute="centerX" secondItem="ErE-Yi-cst" secondAttribute="centerX" id="9LD-WG-eNj"/>
<constraint firstItem="274-Bq-aZO" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="9pf-Ob-PP7"/>
<constraint firstItem="e0u-v7-tRz" firstAttribute="top" secondItem="ilD-ZX-Ker" secondAttribute="bottom" constant="20" id="G53-pc-ZkD"/>
<constraint firstAttribute="centerX" secondItem="Hfi-RE-sgf" secondAttribute="centerX" id="JQc-E1-ZPv"/>
<constraint firstItem="ilD-ZX-Ker" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="JXK-u5-Leb"/>
<constraint firstItem="274-Bq-aZO" firstAttribute="top" secondItem="e0u-v7-tRz" secondAttribute="bottom" constant="20" id="L5e-FL-vfy"/>
<constraint firstItem="Hfi-RE-sgf" firstAttribute="top" secondItem="274-Bq-aZO" secondAttribute="bottom" constant="18" id="Niq-vj-b4l"/>
<constraint firstAttribute="trailingMargin" secondItem="274-Bq-aZO" secondAttribute="trailing" constant="20" id="PZE-4Q-eay"/>
<constraint firstItem="e0u-v7-tRz" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="Plo-NJ-jAG"/>
<constraint firstItem="B4U-QD-nvc" firstAttribute="top" secondItem="Hfi-RE-sgf" secondAttribute="bottom" constant="17" id="QwW-vc-DL6"/>
<constraint firstAttribute="centerX" secondItem="B4U-QD-nvc" secondAttribute="centerX" id="cVc-KL-dCS"/>
<constraint firstItem="EJT-vP-NV4" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="80" id="kBQ-XU-4AK"/>
<constraint firstAttribute="trailingMargin" secondItem="ilD-ZX-Ker" secondAttribute="trailing" constant="20" id="m1o-gm-igX"/>
<constraint firstAttribute="trailingMargin" secondItem="e0u-v7-tRz" secondAttribute="trailing" constant="20" id="oFC-KM-ulQ"/>
<constraint firstItem="ErE-Yi-cst" firstAttribute="top" secondItem="B4U-QD-nvc" secondAttribute="bottom" constant="14" id="wBt-RD-KaP"/>
</constraints>
</view>
</viewController>
Expand Down
40 changes: 40 additions & 0 deletions LeanCloudSocialDemo/LeanCloudSocialDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ - (IBAction)weiboLogin:(id)sender {
} toPlatform:AVOSCloudSNSSinaWeibo];
}

- (IBAction)weiboLogin2:(id)sender {
//此处的 URL 从网站管理台获取,组件->社交
[AVOSCloudSNS loginWithURL:[NSURL URLWithString:@"https://leancloud.cn/1.1/sns/goto/vdhgf2lq96udqd73"] callback:^(id object, NSError *error) {
NSLog(@"object : %@, error : %@", object, error);
if ([self filerError:error]) {
[AVUser loginWithAuthData:object platform:AVOSCloudSNSPlatformWeiBo block:^(AVUser *user, NSError *error) {
if ([self filerError:error]) {
[self alert:@"登录成功"];
NSLog(@"user : %@", user);
}
}];
}
}];
}

- (IBAction)qzoneLogin:(id)sender {
_qqSucc = NO;
[AVOSCloudSNS loginWithCallback:^(id object, NSError *error) {
Expand All @@ -78,6 +93,12 @@ - (IBAction)qzoneLogin:(id)sender {
} toPlatform:AVOSCloudSNSQQ];
}

- (IBAction)qzoneLogin2:(id)sender {
[AVOSCloudSNS loginWithURL:[NSURL URLWithString:@"https://leancloud.cn/1.1/sns/goto/36wvmahsj3davi90"] callback:^(id object, NSError *error) {
NSLog(@"object : %@ error: %@", object, error);
}];
}

- (IBAction)weixinLogin:(id)sender {
_weixinSucc = NO;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"注意" message:@"本 Demo 尚未实现微信账号登录,请你自己申请微信开放平台账号,并导入。" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
Expand All @@ -90,9 +111,28 @@ - (IBAction)renrenLogin:(id)sender {
[alert show];
}

- (IBAction)wechatLogin:(id)sender {
[AVOSCloudSNS loginWithURL:[NSURL URLWithString:@"https://leancloud.cn/1.1/sns/goto/1t261wmvqzthpx0y"] callback:^(id object, NSError *error) {
NSLog(@"object : %@ error: %@", object, error);
}];
}

- (IBAction)unwindToMainMenu:(UIStoryboardSegue*)sender
{
}

- (void)alert:(NSString *)message {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}

- (BOOL)filerError:(NSError *)error {
if (error) {
[self alert:[error localizedDescription]];
return NO;
}
return YES;
}


@end