Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,53 @@
//
// UMComLoginDelegate.h
// UMCommunity
//
// Created by Gavin Ye on 11/11/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComResouceDefines.h"
typedef void(^LoginCompletion)(id responseObject, NSError *error);
@class UMComFeed, UMComLoginUser, UMComUser;
@protocol UMComLoginDelegate <NSObject>
@optional
/**
设置自定义登录的Appkey
*/
- (void)setAppKey:(NSString *)appKey;
/**
自定义登录或者自定义分享处理URL地址
@param 应用回传的URL地址
@returns 处理结果
*/
- (BOOL)handleOpenURL:(NSURL *)url;
/**
处理自定义登录,在友盟微社区没有登录情况下点击遇到需要登录的按钮,就会触发此方法
@param viewController 父ViewController
@param LoadDataCompletion 登录完成的回调
*/
- (void)presentLoginViewController:(UIViewController *)viewController finishResponse:(LoginCompletion)completion;
- (void)handleLoginError:(NSError *)error inViewController:(UIViewController *)rootViewController withLoginData:(UMComLoginUser *)loginUser;
- (void)updateProfileInViewController:(UIViewController *)rootViewController withLoginData:(UMComLoginUser *)loginUser completion:(dispatch_block_t)completion;
- (void)handleEventAfterRegister:(UIViewController *)rootViewController completion:(dispatch_block_t)completion;
@end
@@ -0,0 +1,88 @@
//
// UMComLoginManager.h
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComLoginUser.h"
#import "UMComLoginDelegate.h"
#import <UMCommunitySDK/UMComDataRequestManager.h>
@interface UMComLoginManager : NSObject
@property (nonatomic, strong) id<UMComLoginDelegate> loginHandler;
+ (UMComLoginManager *)shareInstance;
/**
* 获取当前是否登录
*/
+ (BOOL)isLogin;
/**
* 提供社区SDK调用,默认使用友盟登录SDK,或者自定义的第三方登录SDK,实现登录功能
*/
+ (void)performLogin:(UIViewController *)viewController completion:(void (^)(id responseObject, NSError *error))completion;
/**
* 用户注销方法
* @warning 调用这个方法退出登录同时会清空数据库(在没登陆的情况下慎重调用)
*/
+ (void)userLogout;
/**
处理SSO跳转回来之后的url
*/
+ (BOOL)handleOpenURL:(NSURL *)url;
@end
@interface UMComLoginManager (LoginRequest)
/**
* 向server发送登录请求的回调
*
* @param responseObject 登录结构
* @param error 错误信息
* @param callbackCompletion 当登录成功后(即error为空),登录页面dismiss动画结束后回调
*/
typedef void (^UMComLoginCompletion)(NSDictionary *responseObject, NSError *error, dispatch_block_t callbackCompletion);
/**
* 用户登录请求:第三方或自有用户系统
*
* @param userAccount 用户信息
* @param completion 请求完成回调
*/
+ (void)requestLoginWithLoginAccount:(UMComLoginUser *)userAccount requestCompletion:(UMComLoginCompletion)completion;
/**
* 用户登录请求:使用微社区用户系统
*
* @param emailAccount 邮箱账号
* @param password 密码
* @param completion 请求完成回调
*/
+ (void)requestLoginWithEmailAccount:(NSString *)emailAccount password:(NSString *)password requestCompletion:(UMComLoginCompletion)completion;
/**
* 用户注册请求:使用微社区用户系统
*
* @param emailAccount 邮箱账号
* @param password 密码
* @param nickName 昵称
* @param completion 请求完成回调
*/
+ (void)requestRegisterWithEmailAccount:(NSString *)emailAccount password:(NSString *)password nickName:(NSString *)nickName requestCompletion:(UMComLoginCompletion)completion;
@end
@@ -0,0 +1,309 @@
//
// UMComLoginManager.m
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import "UMComLoginManager.h"
#import <UMCommunitySDK/UMComSession.h>
#import "UMComMessageManager.h"
#import "UMComShowToast.h"
#import <UMComFoundation/UMUtils.h>
#import "UMComNavigationController.h"
#import <UMComNetwork/UMComHttpCode.h>
#import <UMComDataStorage/UMComDataBaseManager.h>
#import <UMCommunitySDK/UMComDataTypeDefine.h>
#import "UMComNotificationMacro.h"
#import <UMCommunitySDK/UMCommunitySDK.h>
@interface UMComLoginManager ()
@property (nonatomic, strong) UIViewController *currentViewController;
@property (nonatomic, copy) void (^loginCompletion)(id responseObject, NSError *error);//登录回调
@property (nonatomic, assign) BOOL didUpdateFinish;
@end
@implementation UMComLoginManager
+ (void)load
{
[self shareInstance];
}
+ (UMComLoginManager *)shareInstance {
static UMComLoginManager *_instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[UMComLoginManager alloc] init];
});
return _instance;
}
- (id)init
{
self = [super init];
if (self) {
[self registerNotifications];
}
return self;
}
- (void)registerNotifications
{
__weak typeof(self) ws = self;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removePushAlias) name:kUserLogoutSucceedNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginWhenReceivedLoginError) name:kUMComUserDidNotLoginErrorNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserverForName:kUMComUpdateAppKeyNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[ws setAppKey:[UMCommunitySDK appKey]];
}];
}
- (void)loginWhenReceivedLoginError
{
[UMComLoginManager performLogin:[UIApplication sharedApplication].keyWindow.rootViewController completion:^(id responseObject, NSError *error) {
}];
}
- (void)setAppKey:(NSString *)appKey
{
if ([self.loginHandler respondsToSelector:@selector(setAppKey:)]) {
[self.loginHandler setAppKey:appKey];
}
}
+ (void)performLogin:(UIViewController *)viewController completion:(void (^)(id responseObject, NSError *error))completion
{
if ([self isLogin]) {
if (completion) {
completion([UMComSession sharedInstance].loginUser,nil);
}
}else if ([self shareInstance].loginHandler) {
id<UMComLoginDelegate> loginHandler = [self shareInstance].loginHandler;
if ([loginHandler respondsToSelector:@selector(presentLoginViewController:finishResponse:)]) {
[self shareInstance].currentViewController = viewController;
[self shareInstance].loginCompletion = completion;
[loginHandler presentLoginViewController:viewController finishResponse:nil];
}
}else{
UMLog(@"There is no implement login delegate method");
}
}
+ (BOOL)isLogin{
BOOL isLogin = ([UMComSession sharedInstance].uid != nil);
return isLogin;
}
+ (BOOL)handleOpenURL:(NSURL *)url
{
if ([[self shareInstance].loginHandler respondsToSelector:@selector(handleOpenURL:)]) {
return [[self shareInstance].loginHandler handleOpenURL:url];
}
return NO;
}
+ (void)userLogout
{
[[UMComLoginManager shareInstance] removePushAlias];
[[UMComSession sharedInstance] userLogout];
[[NSNotificationCenter defaultCenter] postNotificationName:kUserLogoutSucceedNotification object:nil];
}
- (void)removePushAlias
{
if ([UMComSession sharedInstance].uid) {
[UMComMessageManager removeAlias:[UMComSession sharedInstance].uid type:kNSAliasKey response:^(id responseObject, NSError *error) {
if (error) {
UMLog(@"remove alias error: %@", error);
}
}];
}
}
+ (void)loginSuccessWithUser:(UMComUser *)loginUser
{
if (![loginUser isKindOfClass:[UMComUser class]]) {
return;
}
[UMComSession sharedInstance].loginUser = loginUser;
[[UMComDataBaseManager shareManager] saveRelatedIDTableWithType:UMComRelatedRegisterUserID withUsers:@[loginUser]];
[[UMComSession sharedInstance] refreshConfigDataWithCompletion:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kUserLoginSucceedNotification object:nil];
[UMComMessageManager addAlias:loginUser.uid type:kNSAliasKey response:^(id responseObject, NSError *error) {
if (error) {
//添加alias失败的话在每次启动时候重新添加
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:@"UMComMessageAddAliasFail"];
[[NSUserDefaults standardUserDefaults] synchronize];
UMLog(@"add alias error: %@", error);
}
}];
}
/**
* 登录流程:
* 1、修复登录错误:若用户名问题,需改后提交成功继续下一步
* 2、保存用户登录数据,注册推送消息,获取配置信息
* 3、若没有触发1,则弹出个人信息页面确认修改
* 4、第一次登录弹出推荐页
* 5、返回调用者
*
* @param responseObject 登录返回user相关数据
* @param error 错误信息
* @param originalUser 第三方平台登录用户信息或待修改信息
*/
+ (void)loginFlowWithData:(NSDictionary *)responseObject error:(NSError *)error originalLoginData:(UMComLoginUser *)originalUser;
{
__weak UMComLoginManager *weakLoginManager = [self shareInstance];
id<UMComLoginDelegate> handler = weakLoginManager.loginHandler;
if (error) {
if ([handler respondsToSelector:@selector(handleLoginError:inViewController:withLoginData:)]) {
[handler handleLoginError:error inViewController:weakLoginManager.currentViewController withLoginData:originalUser];
}
return;
}
UMComUser *loginUser = responseObject[@"data"];
dispatch_block_t returnBlock = ^{
SafeCompletionDataAndError(weakLoginManager.loginCompletion, [UMComSession sharedInstance].uid, nil);
weakLoginManager.loginCompletion = nil;
weakLoginManager.currentViewController = nil;
};
if (loginUser) {
[self loginSuccessWithUser:loginUser];
/**
* 第一次登录逻辑
*/
if ([loginUser.registered integerValue] == 0) {
dispatch_block_t afterRegisterEvent = ^{
/**
* 处理第一次登陆后事务,如展示推荐等
*/
if ([handler respondsToSelector:@selector(handleEventAfterRegister:completion:)]) {
[handler handleEventAfterRegister:[self shareInstance].currentViewController completion:returnBlock];
} else {
returnBlock();
}
};
/**
* 处理第一次登陆后个人信息的修改
*/
if ([handler respondsToSelector:@selector(updateProfileInViewController:withLoginData:completion:)]) {
[handler updateProfileInViewController:[self shareInstance].currentViewController withLoginData:originalUser completion:afterRegisterEvent];
} else {
afterRegisterEvent();
}
} else {
returnBlock();
}
} else {
returnBlock();
}
}
@end
@implementation UMComLoginManager (LoginRequest)
+ (void)requestLoginWithLoginAccount:(UMComLoginUser *)userAccount requestCompletion:(UMComLoginCompletion)completion
{
UMComDataRequestManager *request = [UMComDataRequestManager defaultManager];
if (userAccount.snsType > 0) {
NSMutableDictionary *context = [NSMutableDictionary dictionary];
context[@"wxunionid"] = userAccount.unionId;
[request userLoginWithName:userAccount.name
source:userAccount.snsType
sourceId:userAccount.usid
icon_url:userAccount.icon_url
gender:userAccount.gender.integerValue
age:userAccount.age.integerValue
custom:userAccount.custom
score:0
levelTitle:nil
level:0
contextDictionary:context
userNameType:userNameDefault
userNameLength:userNameLengthDefault completion:^(NSDictionary *responseObject, NSError *error) {
if (completion) {
completion(responseObject, error, ^{
[self loginFlowWithData:responseObject error:error originalLoginData:userAccount];
});
}
}];
} else {
[request userCustomAccountLoginWithName:userAccount.name
sourceId:userAccount.usid
icon_url:userAccount.icon_url
gender:userAccount.gender.integerValue
age:userAccount.age.integerValue
custom:userAccount.custom
score:0
levelTitle:nil
level:0
contextDictionary:nil
userNameType:userNameDefault
userNameLength:userNameLengthDefault completion:^(NSDictionary *responseObject, NSError *error) {
if (completion) {
completion(responseObject, error, ^{
[self loginFlowWithData:responseObject error:error originalLoginData:userAccount];
});
}
}];
}
}
+ (void)requestLoginWithEmailAccount:(NSString *)emailAccount password:(NSString *)password requestCompletion:(UMComLoginCompletion)completion
{
if (![emailAccount isKindOfClass:[NSString class]] ||
![password isKindOfClass:[NSString class]] ||
emailAccount.length == 0 || password.length == 0) {
UMLog(@"%s: invalid params", __func__);
return;
}
[[UMComDataRequestManager defaultManager] userLoginInUMCommunity:emailAccount password:password response:^(NSDictionary *responseObject, NSError *error) {
if (completion) {
completion(responseObject, error, ^{
[self loginFlowWithData:responseObject error:error originalLoginData:nil];
});
}
}];
}
+ (void)requestRegisterWithEmailAccount:(NSString *)emailAccount password:(NSString *)password nickName:(NSString *)nickName requestCompletion:(UMComLoginCompletion)completion
{
if (![emailAccount isKindOfClass:[NSString class]] ||
![password isKindOfClass:[NSString class]] ||
![nickName isKindOfClass:[NSString class]] ||
emailAccount.length == 0 || password.length == 0 || nickName.length == 0) {
UMLog(@"%s: invalid params", __func__);
return;
}
[[UMComDataRequestManager defaultManager] userSignUpUMCommunity:emailAccount password:password nickName:nickName response:^(NSDictionary *responseObject, NSError *error) {
if (completion) {
completion(responseObject, error, ^{
[self loginFlowWithData:responseObject error:error originalLoginData:nil];
});
}
}];
}
@end
@@ -0,0 +1,34 @@
//
// UMComLoginViewController.h
// UMCommunity
//
// Created by wyq.Cloudayc on 5/11/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComViewController.h"
@interface UMComLoginViewController : UMComViewController
/**
* community login
*/
@property (weak, nonatomic) IBOutlet UITextField *accountField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@property (weak, nonatomic) IBOutlet UIButton *registerButton;
@property (weak, nonatomic) IBOutlet UIImageView *accountIcon;
@property (weak, nonatomic) IBOutlet UIImageView *passwordIcon;
@property (weak, nonatomic) IBOutlet UIView *accountColorView;
@property (weak, nonatomic) IBOutlet UIView *pwdColorView;
- (instancetype)initWithExclusiveLogin:(BOOL)exclusive;
- (IBAction)forgotPassword:(id)sender;
- (IBAction)login:(id)sender;
- (IBAction)registerAccount:(id)sender;
@end
@@ -0,0 +1,217 @@
//
// UMComLoginViewController.m
// UMCommunity
//
// Created by wyq.Cloudayc on 5/11/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComLoginViewController.h"
#import "UMComRegisterViewController.h"
#import "UMComResouceDefines.h"
#import <UMComFoundation/UMComKit+String.h>
#import "UIViewController+UMComAddition.h"
#import "UMComShowToast.h"
#import "UMComProgressHUD.h"
#import <UMComFoundation/UMUtils.h>
#import <UMComDataStorage/UMComUser.h>
#import <UMComDataStorage/UMComImageUrl.h>
#import <UMCommunitySDK/UMComDataRequestManager.h>
#import <UMComFoundation/UMComKit+Color.h>
@interface UMComLoginViewController ()
@property (nonatomic, weak) UITextField *currentField;
@property (nonatomic, assign) BOOL exclusiveLogin;
@end
@implementation UMComLoginViewController
- (instancetype)init
{
if (self = [self initWithNibName:@"UMComLoginViewController" bundle:nil]) {
self.exclusiveLogin = NO;
}
return self;
}
- (instancetype)initWithExclusiveLogin:(BOOL)exclusive
{
if (self = [self init]) {
self.exclusiveLogin = exclusive;
}
return self;
}
- (void)checkLoadPlatformLoginView
{
if (_exclusiveLogin) {
return;
}
SEL initLoginPlatformViewSelector = NSSelectorFromString(@"plugInViewController:");
Class PlatformViewClass = NSClassFromString(@"UMComLoginPlatformView");
if ([[PlatformViewClass class] respondsToSelector:initLoginPlatformViewSelector]) {
[PlatformViewClass performSelector:initLoginPlatformViewSelector withObject:self];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = UMComColorWithHexString(@"#E1E6E9");
[self setForumUITitle:UMComLocalizedString(@"um_com_login", @"登录")];
[self initViews];
[self checkLoadPlatformLoginView];
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.leftBarButtonItems = nil;
UIButton *closeButon = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButon setImage:UMComImageWithImageName(@"close") forState:UIControlStateNormal];
[closeButon addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
closeButon.frame = CGRectMake(0.f, 0.f, 22.f, 22.f);
UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithCustomView:closeButon];
[self.navigationItem setLeftBarButtonItem:closeItem];
UIView *placeHolderView = [[UIView alloc] init];
placeHolderView.frame = CGRectMake(0.f, 0.f, 22.f, 22.f);
UIBarButtonItem *placeHolderButton = [[UIBarButtonItem alloc] initWithCustomView:placeHolderView];
[self.navigationItem setRightBarButtonItem:placeHolderButton];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)initViews
{
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
[_accountIcon setImage:UMComImageWithImageName(@"userid")];
[_passwordIcon setImage:UMComImageWithImageName(@"keyword")];
_registerButton.layer.borderWidth = 1.f;
_registerButton.layer.borderColor = UMComColorWithHexString(@"#469EF8").CGColor;
UITapGestureRecognizer *tapClose = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[self.view addGestureRecognizer:tapClose];
}
- (IBAction)forgotPassword:(id)sender {
[_passwordField resignFirstResponder];
[_accountField resignFirstResponder];
if (_accountField.text.length == 0) {
[UMComShowToast accountEmailEmpty];
return;
}
if (![UMComKit checkEmailFormat:_accountField.text]) {
[UMComShowToast accountEmailInvalid];
return;
}
[[UMComDataRequestManager defaultManager] userPasswordForgetForUMCommunity:_accountField.text response:^(NSDictionary *responseObject, NSError *error) {
if (error) {
[UMComShowToast showFetchResultTipWithError:error];
} else {
[UMComShowToast accountFindPasswordSuccess];
}
}];
}
- (IBAction)login:(id)sender {
[_passwordField resignFirstResponder];
[_accountField resignFirstResponder];
if (_accountField.text.length == 0) {
[UMComShowToast accountEmailEmpty];
return;
}
if (![UMComKit checkEmailFormat:_accountField.text]) {
[UMComShowToast accountEmailInvalid];
return;
}
if (_passwordField.text.length == 0) {
[UMComShowToast accountPasswordEmpty];
return;
}
if (_passwordField.text.length < 6 || _passwordField.text.length > 18 || ![UMComKit includeAlphabetOrDigitOnly:_passwordField.text]) {
[UMComShowToast accountPasswordInvalid];
return;
}
//加入等待框
UMComProgressHUD *hud = [UMComProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.label.text = UMComLocalizedString(@"um_com_loginingContent",@"登录中...");
hud.label.backgroundColor = [UIColor clearColor];
__weak typeof(self) ws = self;
[UMComLoginManager requestLoginWithEmailAccount:_accountField.text password:_passwordField.text requestCompletion:^(NSDictionary *responseObject, NSError *error, dispatch_block_t completion) {
[hud hideAnimated:YES];
if (error) {
[UMComShowToast showFetchResultTipWithError:error];
} else {
[UMComShowToast accountLoginSuccess];
[ws.navigationController dismissViewControllerAnimated:YES completion:completion];
}
}];
}
- (IBAction)registerAccount:(id)sender {
UMComRegisterViewController *registerVC = [[UMComRegisterViewController alloc] init];
[self.navigationController pushViewController:registerVC animated:YES];
}
#pragma mark - UITextField delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
self.currentField = textField;
[self refreshColorView];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self refreshColorView];
}
#pragma mark - event
- (void)refreshColorView
{
_accountColorView.hidden = [_accountField isFirstResponder];
_pwdColorView.hidden = [_passwordField isFirstResponder];
}
- (void)hideKeyboard
{
[_currentField resignFirstResponder];
}
- (void)close
{
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
@end
@@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UMComLoginViewController">
<connections>
<outlet property="accountColorView" destination="hKX-4Q-d6g" id="9oa-Oj-ThK"/>
<outlet property="accountField" destination="5J0-WW-KgS" id="idu-HE-F1s"/>
<outlet property="accountIcon" destination="JII-aD-rCG" id="n0O-tR-GAj"/>
<outlet property="passwordField" destination="oIt-Hg-Kdv" id="YRY-0B-LJF"/>
<outlet property="passwordIcon" destination="gE9-uD-XZv" id="Gem-23-57E"/>
<outlet property="pwdColorView" destination="toK-cn-6hG" id="WhT-co-V26"/>
<outlet property="registerButton" destination="1Bp-56-HWj" id="PDM-wT-Cyy"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rxC-n2-48U" userLabel="account_bar">
<rect key="frame" x="0.0" y="15" width="600" height="108"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hKX-4Q-d6g" userLabel="account_color_view">
<rect key="frame" x="0.0" y="0.0" width="600" height="54"/>
<color key="backgroundColor" red="0.94509803921568625" green="0.96470588235294119" blue="0.96862745098039216" alpha="1" colorSpace="calibratedRGB"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="toK-cn-6hG" userLabel="pwd_color_view">
<rect key="frame" x="0.0" y="54" width="600" height="54"/>
<color key="backgroundColor" red="0.94509803920000002" green="0.96470588239999999" blue="0.96862745100000003" alpha="1" colorSpace="calibratedRGB"/>
</view>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="请输入有效邮箱,便于找回密码" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="5J0-WW-KgS" userLabel="account_input">
<rect key="frame" x="57" y="10" width="523" height="34"/>
<constraints>
<constraint firstAttribute="height" constant="34" id="70j-gl-TkV"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="-1" id="oBL-x3-4Og"/>
</connections>
</textField>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="JII-aD-rCG" userLabel="account_icon">
<rect key="frame" x="20" y="16" width="22" height="22"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="gdl-sd-Zzw"/>
<constraint firstAttribute="width" constant="22" id="ouW-5G-DD4"/>
</constraints>
</imageView>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="请输入密码" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="oIt-Hg-Kdv" userLabel="password_input">
<rect key="frame" x="57" y="64" width="523" height="34"/>
<constraints>
<constraint firstAttribute="height" constant="34" id="95R-ni-5SI"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
<connections>
<outlet property="delegate" destination="-1" id="AJT-5I-tbF"/>
</connections>
</textField>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="gE9-uD-XZv" userLabel="password_icon">
<rect key="frame" x="20" y="70" width="22" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="22" id="93O-sU-PYW"/>
<constraint firstAttribute="height" constant="22" id="vn5-Df-Ibp"/>
</constraints>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Jl-HR-dKG" userLabel="line">
<rect key="frame" x="57" y="53.5" width="543" height="1"/>
<color key="backgroundColor" red="0.87450980392156863" green="0.87450980392156863" blue="0.87450980392156863" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="tH4-Aj-SyM"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="6Jl-HR-dKG" firstAttribute="centerY" secondItem="rxC-n2-48U" secondAttribute="centerY" id="1kF-m0-xBZ"/>
<constraint firstItem="oIt-Hg-Kdv" firstAttribute="leading" secondItem="gE9-uD-XZv" secondAttribute="trailing" constant="15" id="2Yg-VU-Ujm"/>
<constraint firstItem="hKX-4Q-d6g" firstAttribute="height" secondItem="rxC-n2-48U" secondAttribute="height" multiplier="0.5" id="3G9-q2-jIM"/>
<constraint firstItem="gE9-uD-XZv" firstAttribute="leading" secondItem="rxC-n2-48U" secondAttribute="leading" constant="20" id="3KW-9n-3mo"/>
<constraint firstAttribute="height" constant="108" id="3em-Yy-6on"/>
<constraint firstAttribute="trailing" secondItem="toK-cn-6hG" secondAttribute="trailing" id="9UO-xH-Lsm"/>
<constraint firstItem="5J0-WW-KgS" firstAttribute="centerY" secondItem="JII-aD-rCG" secondAttribute="centerY" id="Ddp-JW-PAf"/>
<constraint firstAttribute="trailing" secondItem="6Jl-HR-dKG" secondAttribute="trailing" id="I8Q-Mc-c9Y"/>
<constraint firstItem="JII-aD-rCG" firstAttribute="top" secondItem="rxC-n2-48U" secondAttribute="top" constant="16" id="Oz5-us-tnd"/>
<constraint firstAttribute="trailing" secondItem="5J0-WW-KgS" secondAttribute="trailing" constant="20" id="Q8F-DQ-fku"/>
<constraint firstItem="oIt-Hg-Kdv" firstAttribute="centerY" secondItem="gE9-uD-XZv" secondAttribute="centerY" id="RzU-5r-ECI"/>
<constraint firstItem="oIt-Hg-Kdv" firstAttribute="leading" secondItem="gE9-uD-XZv" secondAttribute="trailing" constant="15" id="Tj4-NF-qhg"/>
<constraint firstAttribute="bottom" secondItem="toK-cn-6hG" secondAttribute="bottom" id="V4y-6Y-lpg"/>
<constraint firstItem="6Jl-HR-dKG" firstAttribute="leading" secondItem="5J0-WW-KgS" secondAttribute="leading" id="ak5-5c-i2G"/>
<constraint firstAttribute="trailing" secondItem="oIt-Hg-Kdv" secondAttribute="trailing" constant="20" id="cRq-iR-DcE"/>
<constraint firstItem="toK-cn-6hG" firstAttribute="height" secondItem="rxC-n2-48U" secondAttribute="height" multiplier="0.5" id="gGC-vy-gPP"/>
<constraint firstItem="hKX-4Q-d6g" firstAttribute="top" secondItem="rxC-n2-48U" secondAttribute="top" id="pVT-h4-k9x"/>
<constraint firstItem="oIt-Hg-Kdv" firstAttribute="centerY" secondItem="gE9-uD-XZv" secondAttribute="centerY" id="qYs-oF-WH1"/>
<constraint firstItem="toK-cn-6hG" firstAttribute="leading" secondItem="rxC-n2-48U" secondAttribute="leading" id="rne-0M-utD"/>
<constraint firstItem="5J0-WW-KgS" firstAttribute="leading" secondItem="JII-aD-rCG" secondAttribute="trailing" constant="15" id="uD4-kY-Xn1"/>
<constraint firstItem="JII-aD-rCG" firstAttribute="leading" secondItem="rxC-n2-48U" secondAttribute="leading" constant="20" id="uyA-Hm-LfG"/>
<constraint firstAttribute="trailing" secondItem="hKX-4Q-d6g" secondAttribute="trailing" id="wLx-KJ-yJk"/>
<constraint firstItem="hKX-4Q-d6g" firstAttribute="leading" secondItem="rxC-n2-48U" secondAttribute="leading" id="wlq-hg-IKw"/>
<constraint firstAttribute="bottom" secondItem="gE9-uD-XZv" secondAttribute="bottom" constant="16" id="yf4-br-O72"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="Tj4-NF-qhg"/>
<exclude reference="qYs-oF-WH1"/>
</mask>
</variation>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="meQ-ij-ubJ" userLabel="forgot">
<rect key="frame" x="528" y="143" width="52" height="16"/>
<constraints>
<constraint firstAttribute="height" constant="16" id="xom-j2-nM8"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="忘记密码">
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="forgotPassword:" destination="-1" eventType="touchUpInside" id="T58-af-AfP"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3Km-Ya-48m" userLabel="line">
<rect key="frame" x="528" y="158" width="52" height="1"/>
<color key="backgroundColor" red="0.27843137254901962" green="0.56862745098039214" blue="0.96470588235294119" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="F6M-3c-3Za"/>
</constraints>
</view>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2re-uF-wff" userLabel="login">
<rect key="frame" x="20" y="179" width="560" height="44"/>
<color key="backgroundColor" red="0.27450980392156865" green="0.61960784313725492" blue="0.97254901960784312" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="53G-lE-PzN"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<state key="normal" title="登 录">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" red="0.90980392160000001" green="0.91764705879999997" blue="0.93333333330000001" alpha="1" colorSpace="calibratedRGB"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="22"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="login:" destination="-1" eventType="touchUpInside" id="Ach-2b-vkp"/>
</connections>
</button>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1Bp-56-HWj" userLabel="register">
<rect key="frame" x="20" y="243" width="560" height="44"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="dgO-jX-FE7"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<state key="normal" title="注 册">
<color key="titleColor" red="0.27450980392156865" green="0.61960784313725492" blue="0.97254901960784312" alpha="1" colorSpace="calibratedRGB"/>
</state>
<state key="highlighted">
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="22"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="registerAccount:" destination="-1" eventType="touchUpInside" id="bAD-8q-SH5"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.88235294117647056" green="0.90196078431372551" blue="0.9137254901960784" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="meQ-ij-ubJ" secondAttribute="trailing" constant="20" id="4z7-Lu-UVZ"/>
<constraint firstItem="3Km-Ya-48m" firstAttribute="bottom" secondItem="meQ-ij-ubJ" secondAttribute="bottom" id="6hq-R8-fXz"/>
<constraint firstItem="1Bp-56-HWj" firstAttribute="top" secondItem="2re-uF-wff" secondAttribute="bottom" constant="20" id="9yp-dD-koh"/>
<constraint firstAttribute="trailing" secondItem="1Bp-56-HWj" secondAttribute="trailing" constant="20" id="DOh-No-9h5"/>
<constraint firstItem="rxC-n2-48U" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="DXd-Fb-ouO"/>
<constraint firstAttribute="trailing" secondItem="2re-uF-wff" secondAttribute="trailing" constant="20" id="GfF-U0-Q4K"/>
<constraint firstItem="2re-uF-wff" firstAttribute="top" secondItem="meQ-ij-ubJ" secondAttribute="bottom" constant="20" id="Pko-XB-haI"/>
<constraint firstItem="1Bp-56-HWj" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="XtY-PF-NNv"/>
<constraint firstItem="rxC-n2-48U" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="15" id="enR-Ox-BUa"/>
<constraint firstItem="2re-uF-wff" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="hHY-QA-9sU"/>
<constraint firstItem="3Km-Ya-48m" firstAttribute="trailing" secondItem="meQ-ij-ubJ" secondAttribute="trailing" id="hQN-pc-Em5"/>
<constraint firstAttribute="trailing" secondItem="rxC-n2-48U" secondAttribute="trailing" id="nTI-Jb-7FK"/>
<constraint firstItem="meQ-ij-ubJ" firstAttribute="top" secondItem="rxC-n2-48U" secondAttribute="bottom" constant="20" id="nwj-bg-GTs"/>
<constraint firstItem="3Km-Ya-48m" firstAttribute="leading" secondItem="meQ-ij-ubJ" secondAttribute="leading" id="tDT-Ku-CbR"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<point key="canvasLocation" x="230" y="25"/>
</view>
</objects>
</document>
@@ -0,0 +1,26 @@
//
// UMComRegisterViewController.h
// UMCommunity
//
// Created by wyq.Cloudayc on 5/11/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComViewController.h"
#import "UMComImageView.h"
@interface UMComRegisterViewController : UMComViewController
//@property (weak, nonatomic) IBOutlet UMComImageView *avatarImageView;
@property (weak, nonatomic) IBOutlet UITextField *accountField;
@property (weak, nonatomic) IBOutlet UITextField *nicknameField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@property (weak, nonatomic) IBOutlet UIButton *passwordHiddenButton;
@property (strong, nonatomic) IBOutletCollection(UIView) NSArray *bars;
- (IBAction)changePassworkHidden:(id)sender;
- (IBAction)registerAccount:(id)sender;
@end
@@ -0,0 +1,160 @@
//
// UMComRegisterViewController.m
// UMCommunity
//
// Created by wyq.Cloudayc on 5/11/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComRegisterViewController.h"
#import "UIViewController+UMComAddition.h"
#import "UMComShowToast.h"
#import "UMComLoginManager.h"
#import "UMComProgressHUD.h"
#import <UMComFoundation/UMComKit+String.h>
#import <UMComFoundation/UMComKit+Color.h>
@interface UMComRegisterViewController ()
@property (nonatomic, weak) UITextField *currentField;
@end
@implementation UMComRegisterViewController
- (instancetype)init
{
if (self = [self initWithNibName:@"UMComRegisterViewController" bundle:nil]) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = UMComColorWithHexString(@"#E1E6E9");
[self initViews];
[self setForumUITitle:UMComLocalizedString(@"um_com_register", @"注册")];
UIView *placeHolderView = [[UIView alloc] init];
placeHolderView.frame = CGRectMake(0.f, 0.f, 22.f, 22.f);
UIBarButtonItem *placeHolderButton = [[UIBarButtonItem alloc] initWithCustomView:placeHolderView];
[self.navigationItem setRightBarButtonItem:placeHolderButton];
[_accountField becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated
{
[_currentField resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)initViews
{
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
// [_avatarImageView setPlaceholderImage:UMComImageWithImageName(@"camera-large")];
[_passwordHiddenButton setBackgroundImage:UMComImageWithImageName(@"showpassword") forState:UIControlStateNormal];
[_passwordHiddenButton setBackgroundImage:UMComImageWithImageName(@"hidepassword") forState:UIControlStateSelected];
_passwordHiddenButton.selected = YES;
_passwordField.placeholder = UMComLocalizedString(@"um_com_password_rule", @"6-18个字母或数字");
_nicknameField.placeholder = UMComLocalizedString(@"um_com_nickname_rule", @"2-20个中英文字符");
}
- (IBAction)changePassworkHidden:(id)sender {
_passwordField.secureTextEntry = !_passwordField.secureTextEntry;
_passwordHiddenButton.selected = _passwordField.secureTextEntry;
}
- (IBAction)registerAccount:(id)sender {
[_currentField resignFirstResponder];
if (![self checkRegisterValid])
return;
//加入等待框
UMComProgressHUD *hud = [UMComProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.label.text = UMComLocalizedString(@"um_com_registeringContent",@"注册中...");
hud.label.backgroundColor = [UIColor clearColor];
__weak typeof(self) ws = self;
[UMComLoginManager requestRegisterWithEmailAccount:_accountField.text password:_passwordField.text nickName:_nicknameField.text requestCompletion:^(NSDictionary *responseObject, NSError *error, dispatch_block_t completion) {
[hud hideAnimated:YES];
if (error) {
[UMComShowToast showFetchResultTipWithError:error];
} else {
[UMComShowToast accountRegisterSuccess];
[ws.navigationController dismissViewControllerAnimated:YES completion:completion];
}
}];
}
- (BOOL)checkRegisterValid
{
if (_accountField.text.length == 0) {
[UMComShowToast accountEmailEmpty];
return NO;
}
if (![UMComKit checkEmailFormat:_accountField.text]) {
[UMComShowToast accountEmailInvalid];
return NO;
}
if (_passwordField.text.length == 0) {
[UMComShowToast accountPasswordEmpty];
return NO;
}
if (_passwordField.text.length < 6 || _passwordField.text.length > 18 || ![UMComKit includeAlphabetOrDigitOnly:_passwordField.text]) {
[UMComShowToast accountPasswordInvalid];
return NO;
}
// 中文或英文
if (_nicknameField.text.length < 2 || _nicknameField.text.length > 20 || [UMComKit includeSpecialCharact:_nicknameField.text]) {
[UMComShowToast accountNicknameInvalid];
return NO;
}
return YES;
}
#pragma mark - FieldDelegate
- (void)clearBarsColor
{
UIColor *normalColor = UMComColorWithHexString(@"#F1F6F7");
for (UIView *v in _bars) {
v.backgroundColor = normalColor;
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
self.currentField = textField;
[self clearBarsColor];
textField.superview.backgroundColor = [UIColor whiteColor];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self clearBarsColor];
}
@end
@@ -0,0 +1,250 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UMComRegisterViewController">
<connections>
<outlet property="accountField" destination="65t-Dm-ggP" id="Fp6-s6-Nv5"/>
<outlet property="nicknameField" destination="XBg-9M-sn1" id="oW5-Md-20J"/>
<outlet property="passwordField" destination="Xtc-WE-lSQ" id="FTB-JT-snk"/>
<outlet property="passwordHiddenButton" destination="29T-6t-gxZ" id="fdf-C2-Xs1"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
<outletCollection property="bars" destination="oAo-e5-x0X" id="zdS-ga-ZwJ"/>
<outletCollection property="bars" destination="4D2-Pa-1mV" id="vlE-Mf-nK8"/>
<outletCollection property="bars" destination="Dgd-aU-HC6" id="VpG-xf-NMW"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0TI-gt-21s" userLabel="avatar">
<rect key="frame" x="0.0" y="15" width="600" height="64"/>
<color key="backgroundColor" red="0.99607843137254903" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="64" id="OuW-rn-KMi"/>
</constraints>
<state key="normal">
<color key="titleColor" red="0.53725490196078429" green="0.54117647058823526" blue="0.5490196078431373" alpha="1" colorSpace="calibratedRGB"/>
</state>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="8i4-mn-m5e" customClass="UMComImageView">
<rect key="frame" x="20" y="25" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="2hQ-Be-PAh"/>
<constraint firstAttribute="height" constant="44" id="rav-Fn-9zU"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="22"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="上传头像" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6Lj-ak-Fko">
<rect key="frame" x="78" y="38" width="56" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.4823529411764706" green="0.4823529411764706" blue="0.49019607843137253" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="oAo-e5-x0X" userLabel="account_bar">
<rect key="frame" x="0.0" y="15" width="600" height="54"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YXQ-0X-BVb" userLabel="line">
<rect key="frame" x="63" y="53" width="537" height="1"/>
<color key="backgroundColor" red="0.87450980389999999" green="0.87450980389999999" blue="0.87450980389999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="bWE-n2-NF3"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="账号" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WI5-wm-IqO" userLabel="account">
<rect key="frame" x="20" y="19" width="28" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.49411764705882355" green="0.49803921568627452" blue="0.50196078431372548" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="请输入有效邮箱,便于找回密码" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="65t-Dm-ggP" userLabel="account_input">
<rect key="frame" x="63" y="10" width="517" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="-1" id="Dmj-KT-u2s"/>
</connections>
</textField>
</subviews>
<color key="backgroundColor" red="0.94509803921568625" green="0.96470588235294119" blue="0.96862745098039216" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="65t-Dm-ggP" firstAttribute="top" secondItem="oAo-e5-x0X" secondAttribute="top" constant="10" id="2z9-dk-wvG"/>
<constraint firstItem="YXQ-0X-BVb" firstAttribute="leading" secondItem="65t-Dm-ggP" secondAttribute="leading" id="7iZ-Dk-Al0"/>
<constraint firstAttribute="height" constant="54" id="AeV-iB-4pP"/>
<constraint firstAttribute="bottom" secondItem="65t-Dm-ggP" secondAttribute="bottom" constant="10" id="MeE-zL-fZo"/>
<constraint firstAttribute="trailing" secondItem="65t-Dm-ggP" secondAttribute="trailing" constant="20" id="gcv-Kx-UuC"/>
<constraint firstItem="65t-Dm-ggP" firstAttribute="centerY" secondItem="WI5-wm-IqO" secondAttribute="centerY" id="gf5-aV-2cp"/>
<constraint firstItem="WI5-wm-IqO" firstAttribute="leading" secondItem="oAo-e5-x0X" secondAttribute="leading" constant="20" id="n0a-8W-qoI"/>
<constraint firstAttribute="bottom" secondItem="YXQ-0X-BVb" secondAttribute="bottom" id="usn-Zw-SHb"/>
<constraint firstItem="65t-Dm-ggP" firstAttribute="leading" secondItem="WI5-wm-IqO" secondAttribute="trailing" constant="15" id="xiC-F7-hpg"/>
<constraint firstItem="WI5-wm-IqO" firstAttribute="centerY" secondItem="oAo-e5-x0X" secondAttribute="centerY" id="zvE-IG-VAu"/>
<constraint firstAttribute="trailing" secondItem="YXQ-0X-BVb" secondAttribute="trailing" id="zz8-D7-jVI"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="gf5-aV-2cp"/>
</mask>
</variation>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4D2-Pa-1mV" userLabel="nickname_bar">
<rect key="frame" x="0.0" y="69" width="600" height="54"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Fc6-oh-GI4" userLabel="line">
<rect key="frame" x="63" y="53" width="537" height="1"/>
<color key="backgroundColor" red="0.87450980389999999" green="0.87450980389999999" blue="0.87450980389999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="Wjm-O3-40V"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="昵称" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tVh-83-fc3" userLabel="nickname">
<rect key="frame" x="20" y="19" width="28" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.4941176471" green="0.49803921569999998" blue="0.50196078430000002" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="XBg-9M-sn1" userLabel="nickname_input">
<rect key="frame" x="63" y="10" width="517" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="-1" id="WLN-P2-1hX"/>
</connections>
</textField>
</subviews>
<color key="backgroundColor" red="0.94509803920000002" green="0.96470588239999999" blue="0.96862745100000003" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="Fc6-oh-GI4" secondAttribute="bottom" id="195-OW-7oF"/>
<constraint firstItem="XBg-9M-sn1" firstAttribute="leading" secondItem="tVh-83-fc3" secondAttribute="trailing" constant="15" id="D7S-TQ-8tL"/>
<constraint firstAttribute="height" constant="54" id="EgM-T5-YRT"/>
<constraint firstAttribute="trailing" secondItem="XBg-9M-sn1" secondAttribute="trailing" constant="20" id="T20-9M-R3l"/>
<constraint firstItem="Fc6-oh-GI4" firstAttribute="leading" secondItem="XBg-9M-sn1" secondAttribute="leading" id="ZWa-G4-j2I"/>
<constraint firstAttribute="bottom" secondItem="XBg-9M-sn1" secondAttribute="bottom" constant="10" id="ZsL-ow-tAv"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="54" id="aa9-jb-FDP"/>
<constraint firstItem="XBg-9M-sn1" firstAttribute="centerY" secondItem="tVh-83-fc3" secondAttribute="centerY" id="bOk-gW-aQp"/>
<constraint firstItem="tVh-83-fc3" firstAttribute="leading" secondItem="4D2-Pa-1mV" secondAttribute="leading" constant="20" id="g9G-uS-YPo"/>
<constraint firstItem="XBg-9M-sn1" firstAttribute="top" secondItem="4D2-Pa-1mV" secondAttribute="top" constant="10" id="ihw-dH-CCf"/>
<constraint firstAttribute="trailing" secondItem="Fc6-oh-GI4" secondAttribute="trailing" id="mRI-vx-TL9"/>
<constraint firstItem="tVh-83-fc3" firstAttribute="centerY" secondItem="4D2-Pa-1mV" secondAttribute="centerY" id="zJ2-KV-tEC"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="bOk-gW-aQp"/>
</mask>
</variation>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Dgd-aU-HC6">
<rect key="frame" x="0.0" y="123" width="600" height="54"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="密码" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="x5G-YW-rCQ" userLabel="password">
<rect key="frame" x="20" y="19" width="28" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.4941176471" green="0.49803921569999998" blue="0.50196078430000002" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Xtc-WE-lSQ" userLabel="password_input">
<rect key="frame" x="63" y="10" width="490" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
<connections>
<outlet property="delegate" destination="-1" id="L8q-qR-7aA"/>
</connections>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="29T-6t-gxZ" userLabel="hide_button">
<rect key="frame" x="558" y="16" width="22" height="22"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="Oeq-0c-40w"/>
<constraint firstAttribute="width" constant="22" id="lNN-18-rkq"/>
</constraints>
<connections>
<action selector="changePassworkHidden:" destination="-1" eventType="touchUpInside" id="qYs-Kw-ThI"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.94509803920000002" green="0.96470588239999999" blue="0.96862745100000003" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="54" id="0mC-SR-oDB"/>
<constraint firstItem="x5G-YW-rCQ" firstAttribute="centerY" secondItem="Dgd-aU-HC6" secondAttribute="centerY" id="91P-tj-I6m"/>
<constraint firstItem="x5G-YW-rCQ" firstAttribute="leading" secondItem="Dgd-aU-HC6" secondAttribute="leading" constant="20" id="A7M-kB-Mho"/>
<constraint firstItem="Xtc-WE-lSQ" firstAttribute="leading" secondItem="x5G-YW-rCQ" secondAttribute="trailing" constant="15" id="Alt-i7-qrQ"/>
<constraint firstItem="29T-6t-gxZ" firstAttribute="centerY" secondItem="Dgd-aU-HC6" secondAttribute="centerY" id="IUT-Zv-zOE"/>
<constraint firstAttribute="height" constant="54" id="Ij6-vA-ybz"/>
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="54" id="QDW-h4-nkb"/>
<constraint firstAttribute="bottom" secondItem="Xtc-WE-lSQ" secondAttribute="bottom" constant="10" id="VHZ-Yw-Kry"/>
<constraint firstItem="Xtc-WE-lSQ" firstAttribute="top" secondItem="Dgd-aU-HC6" secondAttribute="top" constant="10" id="W7r-d1-YyQ"/>
<constraint firstItem="29T-6t-gxZ" firstAttribute="leading" secondItem="Xtc-WE-lSQ" secondAttribute="trailing" constant="5" id="p2x-jz-aLQ"/>
<constraint firstItem="Xtc-WE-lSQ" firstAttribute="centerY" secondItem="x5G-YW-rCQ" secondAttribute="centerY" id="sgn-Yb-wAs"/>
<constraint firstAttribute="trailing" secondItem="29T-6t-gxZ" secondAttribute="trailing" constant="20" id="shD-Io-c8u"/>
</constraints>
<string key="userLabel" base64-UTF8="YES">
BHBhc3N3b3JkX2Jhcg
</string>
<variation key="default">
<mask key="constraints">
<exclude reference="sgn-Yb-wAs"/>
</mask>
</variation>
</view>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HCm-NM-Vxm" userLabel="register">
<rect key="frame" x="20" y="217" width="560" height="44"/>
<color key="backgroundColor" red="0.27450980392156865" green="0.61960784313725492" blue="0.97254901960784312" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="vDN-iy-H33"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<state key="normal" title="完成注册">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" red="0.90980392160000001" green="0.91764705879999997" blue="0.93333333330000001" alpha="1" colorSpace="calibratedRGB"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="22"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="registerAccount:" destination="-1" eventType="touchUpInside" id="c9j-yX-dx4"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.88235294117647056" green="0.90196078431372551" blue="0.9137254901960784" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="8i4-mn-m5e" firstAttribute="leading" secondItem="0TI-gt-21s" secondAttribute="leading" constant="20" id="16Y-IV-mhC"/>
<constraint firstItem="6Lj-ak-Fko" firstAttribute="centerY" secondItem="8i4-mn-m5e" secondAttribute="centerY" id="2t3-Ib-t1m"/>
<constraint firstItem="0TI-gt-21s" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="3hN-Oe-wiK"/>
<constraint firstAttribute="trailing" secondItem="4D2-Pa-1mV" secondAttribute="trailing" id="64r-uT-gew"/>
<constraint firstItem="oAo-e5-x0X" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="9Ye-Ph-9yg"/>
<constraint firstItem="oAo-e5-x0X" firstAttribute="top" secondItem="0TI-gt-21s" secondAttribute="bottom" priority="750" constant="15" id="DZl-cx-ZlA"/>
<constraint firstAttribute="trailing" secondItem="oAo-e5-x0X" secondAttribute="trailing" id="INg-ij-VcL"/>
<constraint firstItem="HCm-NM-Vxm" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="IaL-Bf-Xpu"/>
<constraint firstItem="8i4-mn-m5e" firstAttribute="centerY" secondItem="0TI-gt-21s" secondAttribute="centerY" id="KRp-9S-fg5"/>
<constraint firstItem="HCm-NM-Vxm" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="Rpp-Dp-o4n"/>
<constraint firstItem="6Lj-ak-Fko" firstAttribute="leading" secondItem="8i4-mn-m5e" secondAttribute="trailing" constant="14" id="TwX-QT-LRL"/>
<constraint firstItem="0TI-gt-21s" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="15" id="UOq-TW-5Lo"/>
<constraint firstItem="HCm-NM-Vxm" firstAttribute="top" secondItem="Dgd-aU-HC6" secondAttribute="bottom" constant="40" id="XoA-Zz-f3A"/>
<constraint firstItem="4D2-Pa-1mV" firstAttribute="top" secondItem="oAo-e5-x0X" secondAttribute="bottom" id="Yjc-jk-1gB"/>
<constraint firstAttribute="trailing" secondItem="Dgd-aU-HC6" secondAttribute="trailing" id="biN-9r-KGo"/>
<constraint firstItem="4D2-Pa-1mV" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="hQF-tI-Apx"/>
<constraint firstAttribute="trailing" secondItem="0TI-gt-21s" secondAttribute="trailing" id="mA9-Qt-pcP"/>
<constraint firstAttribute="trailing" secondItem="HCm-NM-Vxm" secondAttribute="trailing" constant="20" id="uet-3V-RXX"/>
<constraint firstItem="Dgd-aU-HC6" firstAttribute="top" secondItem="4D2-Pa-1mV" secondAttribute="bottom" id="uvo-3J-RLL"/>
<constraint firstItem="oAo-e5-x0X" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="15" id="y5o-Un-Cd0"/>
<constraint firstItem="Dgd-aU-HC6" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="ypK-kR-xQT"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<point key="canvasLocation" x="426" y="396"/>
</view>
</objects>
</document>
@@ -0,0 +1,18 @@
//
// UMengLoginHandler.h
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComLoginManager.h"
#import "UMComLoginViewController.h"
#import "UMComLoginDelegate.h"
@interface UMComLoginHandler : NSObject<UMComLoginDelegate>
+ (void)bindLoginHandler;
@end
@@ -0,0 +1,105 @@
//
// UMengLoginHandler.m
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import "UMComLoginHandler.h"
#import "UMComNavigationController.h"
#import <UMComNetwork/UMComHttpCode.h>
#import "UMComProfileSettingController.h"
@interface UMComLoginHandler()
@end
@implementation UMComLoginHandler
static UMComLoginHandler *_instance = nil;
+ (void)load
{
[self bindLoginHandler];
}
+ (void)bindLoginHandler
{
[UMComLoginManager shareInstance].loginHandler = [[self alloc] init];
}
- (void)setAppKey:(NSString *)appKey
{
}
- (BOOL)handleOpenURL:(NSURL *)url
{
return NO;
}
- (void)presentLoginViewController:(UIViewController *)viewController finishResponse:(void (^)(id, NSError *))completion
{
UMComLoginViewController *loginViewController = [[UMComLoginViewController alloc] init];
UMComNavigationController *navigationController = [[UMComNavigationController alloc] initWithRootViewController:loginViewController];
[viewController presentViewController:navigationController animated:YES completion:nil];
}
- (void)handleLoginError:(NSError *)error inViewController:(UIViewController *)rootViewController withLoginData:(UMComLoginUser *)loginUser
{
if (error.code == ERR_CODE_USER_NAME_LENGTH_ERROR || error.code == ERR_CODE_USER_NAME_SENSITIVE || error.code == ERR_CODE_USER_NAME_DUPLICATE || error.code == ERR_CODE_USER_NAME_CONTAINS_ILLEGAL_CHARS) {
[self updateProfileInViewController:rootViewController withLoginData:loginUser forRegisterSetting:YES completion:nil];
}
}
- (void)updateProfileInViewController:(UIViewController *)rootViewController withLoginData:(UMComLoginUser *)loginUser completion:(dispatch_block_t)completion
{
if (loginUser.updatedProfile) {
if (completion) {
completion();
}
return;
}
[self updateProfileInViewController:rootViewController withLoginData:loginUser forRegisterSetting:NO completion:completion];
}
- (void)updateProfileInViewController:(UIViewController *)rootViewController withLoginData:(UMComLoginUser *)loginUser forRegisterSetting:(BOOL)forRegister completion:(dispatch_block_t)completion
{
UMComProfileSettingController *profileController = [[UMComProfileSettingController alloc] init];
profileController.forRegister = forRegister;
profileController.updateCompletion = completion;
profileController.userAccount = loginUser;
UMComNavigationController *profileNaviController = [[UMComNavigationController alloc] initWithRootViewController:profileController];
[rootViewController presentViewController:profileNaviController animated:YES completion:nil];
}
#pragma mark - 显示推荐页面
- (void)handleEventAfterRegister:(UIViewController *)rootViewController completion:(dispatch_block_t)completion
{
[self showRecommendViewControllerWithLoginViewController:rootViewController loginComletion:completion];
}
- (void)showRecommendViewControllerWithLoginViewController:(UIViewController *)viewController loginComletion:(void (^)())loginCompletion
{
[self showRecommendTopicWithViewController:viewController completion:^(UIViewController *recommendTopicVC) {
[self showRecommendUserWithViewController:recommendTopicVC completion:^(UIViewController *recommendUserVC) {
[recommendUserVC dismissViewControllerAnimated:YES completion:loginCompletion];
}];
}];
}
- (void)showRecommendUserWithViewController:(UIViewController *)viewController
completion:(void (^)(UIViewController *recommendUserVC))completion
{
completion(nil);
}
- (void)showRecommendTopicWithViewController:(UIViewController *)viewController completion:(void (^)(UIViewController *recommendTopicVC))completion
{
completion(nil);
}
@end
@@ -0,0 +1,123 @@
//
// UMComLoginUser.h
// UMCommunity
//
// Created by wyq.Cloudayc on 7/15/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UMComNetwork/UMComNetworkConstant.h>
/**
使用第三方登录方法后得到的登录数据构造此类
*/
@interface UMComLoginUser : NSObject
/**
required sns对应的平台类型,例如`UMComSnsTypeSina`对应新浪
*/
@property (nonatomic, assign) UMComSnsType snsType;
/**
required sns对应的平台名称,例如`sina`对应新浪
*/
@property (nonatomic, copy, readonly) NSString *snsPlatformName;
/**
required, sns平台的用户id
*/
@property (nonatomic, copy) NSString * usid;
/**
required, sns平台的用户昵称
*/
@property (nonatomic, copy) NSString * name;
/**
用户头像的链接地址
*/
@property (nonatomic, copy) NSString * icon_url;
/**
用户头像
*/
@property (nonatomic, strong) UIImage *iconImage;
/**
用户年龄
*/
@property (nonatomic, strong) NSNumber * age;
/**
用户性别,1代表男性,0代表女性
*/
@property (nonatomic, strong) NSNumber * gender;
/**
用户自定义字段
*/
@property (nonatomic, copy) NSString * custom;
/**
等级
*/
@property (nonatomic, strong) NSNumber *level;
/**
积分
*/
@property (nonatomic, strong) NSNumber *score;
/**
等级名称
*/
@property (nonatomic, copy) NSString *level_title;
/**SDK version 2.1.2 start**/
/**
用户名字符类型限制
*/
@property (nonatomic, assign) UMComUserNameType userNameType;
/**
用户名长度限制
*/
@property (nonatomic, assign) UMComUserNameLength userNameLength;
/**SDK version 2.1.2 end**/
/**
微信授权的unionId
*/
@property (nonatomic, assign) NSString *unionId;
@property (nonatomic, assign) BOOL updatedProfile;
/**
初始化方法
@param snsType 平台类型
@returns 用户账号对象
*/
- (id)initWithSnsType:(UMComSnsType)snsType;
@end
@@ -0,0 +1,37 @@
//
// UMComLoginUser.m
// UMCommunity
//
// Created by wyq.Cloudayc on 7/15/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComLoginUser.h"
@interface UMComLoginUser()
@end
@implementation UMComLoginUser
- (instancetype)init
{
self = [super init];
if (self) {
_snsType = UMComSnsTypeNone;
_updatedProfile = NO;
}
return self;
}
- (id)initWithSnsType:(UMComSnsType)snsType
{
if (self = [self init]) {
self.snsType = snsType;
}
return self;
}
@end
@@ -0,0 +1,16 @@
//
// UMengLoginHandler.h
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComLoginDelegate.h"
@interface UMComSimpleLoginHandler : NSObject<UMComLoginDelegate>
+ (void)bindLoginHandler;
@end
@@ -0,0 +1,61 @@
//
// UMengLoginHandler.m
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import "UMComSimpleLoginHandler.h"
#import "UMComNavigationController.h"
#import "UMComLoginManager.h"
#import "UMComLoginViewController.h"
#import "UMComSimpleProfileSettingController.h"
@interface UMComSimpleLoginHandler()
@end
@implementation UMComSimpleLoginHandler
static UMComSimpleLoginHandler *_instance = nil;
+ (void)load
{
[self bindLoginHandler];
}
+ (void)bindLoginHandler
{
[UMComLoginManager shareInstance].loginHandler = [[self alloc] init];
}
- (void)presentLoginViewController:(UIViewController *)viewController finishResponse:(LoginCompletion)completion
{
UMComLoginViewController *loginViewController = [[UMComLoginViewController alloc] initWithExclusiveLogin:YES];
UMComNavigationController *navigationController = [[UMComNavigationController alloc] initWithRootViewController:loginViewController];
if (viewController) {
[viewController presentViewController:navigationController animated:YES completion:nil];
}else{
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:navigationController animated:YES completion:nil];
}
}
- (void)updateProfileInViewController:(UIViewController *)rootViewController withLoginData:(UMComLoginUser *)loginUser completion:(dispatch_block_t)completion
{
[self updateProfileInViewController:rootViewController completion:completion];
}
- (void)updateProfileInViewController:(UIViewController *)viewController completion:(dispatch_block_t)completion
{
UMComSimpleProfileSettingController *VC = [[UMComSimpleProfileSettingController alloc] init];
VC.hideLogout = YES;
VC.updateCompletion = completion;
UMComNavigationController *rootLoginNav = [[UMComNavigationController alloc] initWithRootViewController:VC];
[viewController.navigationController presentViewController:rootLoginNav animated:YES completion:nil];
}
@end
@@ -0,0 +1,25 @@
//
// UMComMessageDelegate.h
// UMCommunity
//
// Created by Gavin Ye on 11/10/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void (^UMComPushDetailViewBlock)(NSString *appkey, NSString *feedID, NSString *commentID, NSDictionary *extraDict);
@protocol UMComMessageDelegate <NSObject>
- (void)startWithAppKey:(NSString *)appKey launchOptions:(NSDictionary *)launchOptions;
- (void)registerDeviceToken:(NSData *)deviceToken;
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo;
- (void)addAlias:(NSString *)name type:(NSString *)type response:(void (^)(id responseObject,NSError *error))handle;
- (void)removeAlias:(NSString *)name type:(NSString *)type response:(void (^)(id responseObject,NSError *error))handle;
@end
@@ -0,0 +1,61 @@
//
// UMComMessageManager.h
// UMCommunity
//
// Created by Gavin Ye on 11/10/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComMessageDelegate.h"
@interface UMComMessageManager : NSObject
+ (UMComMessageManager *)sharedInstance;
/**
设置消息处理delegate对象
*/
+ (void)setMessageDelegate:(id<UMComMessageDelegate>)messageDelegate;
/**
实现'- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions'方法
*/
+ (void)startWithOptions:(NSDictionary *)launchOptions;
/**
实现方法'- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken'
*/
+ (void)registerDeviceToken:(NSData *)deviceToken;
/**
实现方法'- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo'
*/
+ (void)didReceiveRemoteNotification:(NSDictionary *)userInfo;
+ (void)handleUserInfo:(NSDictionary *)userInfo;
/**
添加别名
*/
+ (void)addAlias:(NSString *)name type:(NSString *)type response:(void (^)(id responseObject,NSError *error))handle;
/**
删除别名
*/
+ (void)removeAlias:(NSString *)name type:(NSString *)type response:(void (^)(id responseObject,NSError *error))handle;
/**
收到对应appkey下的推送至feed详情页通知
*/
+ (void)remoteNotificationForEnterDetailView:(UMComPushDetailViewBlock)handle;
@end
@@ -0,0 +1,239 @@
//
// UMComMessageManager.m
// UMCommunity
//
// Created by Gavin Ye on 11/10/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import "UMComMessageManager.h"
#import <UMComFoundation/UMUtils.h>
#import "UMComLoginManager.h"
#import "UMComNavigationController.h"
#import "UMComResouceDefines.h"
#import <UMCommunitySDK/UMComSession.h>
#import <UMCommunitySDK/UMCommunitySDK.h>
@interface UMComMessageManager()
@property (nonatomic, strong) id<UMComMessageDelegate>messageDelegate;
@property (nonatomic, strong) UMComPushDetailViewBlock pushViewBlock;
@end
@implementation UMComMessageManager
+ (void)load
{
[self sharedInstance];
}
+ (UMComMessageManager *)sharedInstance {
static UMComMessageManager *_instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[UMComMessageManager alloc] init];
});
return _instance;
}
- (id)init
{
self = [super init];
if (self) {
self.messageDelegate = [[NSClassFromString(@"UMComUMengMessageHandler") alloc] init];
[self registerNotifications];
}
return self;
}
- (void)registerNotifications
{
__weak typeof(self) ws = self;
[[NSNotificationCenter defaultCenter] addObserverForName:kUMComUpdateAppKeyNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[ws setAppkey:[UMCommunitySDK appKey]];
}];
}
+ (void)setMessageDelegate:(id<UMComMessageDelegate>)messageDelegate
{
if (messageDelegate) {
[self sharedInstance].messageDelegate = messageDelegate;
} else {
UMLog(@"you must set a message delegate!");
}
}
- (void)setAppkey:(NSString *)appKey
{
if (!appKey) {
UMLog(@"appkey can not be nil!");
}
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"UMComMessageAddAliasFail"] boolValue]) {
if ([UMComSession sharedInstance].uid) {
[UMComMessageManager addAlias:[UMComSession sharedInstance].uid type:kNSAliasKey response:^(id responseObject, NSError *error) {
if (error) {
//添加alias失败的话在每次启动时候重新添加
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:@"UMComMessageAddAliasFail"];
[[NSUserDefaults standardUserDefaults] synchronize];
} else {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"UMComMessageAddAliasFail"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}];
}
}
}
+ (void)startWithOptions:(NSDictionary *)launchOptions
{
id<UMComMessageDelegate> messageDelegate = [self sharedInstance].messageDelegate;
if (messageDelegate && [messageDelegate respondsToSelector:@selector(startWithAppKey:launchOptions:)]) {
[messageDelegate startWithAppKey:[UMCommunitySDK appKey] launchOptions:launchOptions];
}
}
+ (void)registerDeviceToken:(NSData *)deviceToken{
id<UMComMessageDelegate> messageDelegate = [self sharedInstance].messageDelegate;
if (messageDelegate && [messageDelegate respondsToSelector:@selector(registerDeviceToken:)]) {
[messageDelegate registerDeviceToken:deviceToken];
}
}
+ (void)didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//如果是接收友盟微社区消息通知, 则刷新未读消息数
if ([userInfo valueForKey:@"umwsq"]) {
[[UMComSession sharedInstance] refreshConfigDataWithCompletion:nil];
}
id<UMComMessageDelegate> messageDelegate = [self sharedInstance].messageDelegate;
if (messageDelegate && [messageDelegate respondsToSelector:@selector(didReceiveRemoteNotification:)]) {
[messageDelegate didReceiveRemoteNotification:userInfo];
}
}
+ (void)addAlias:(NSString *)name type:(NSString *)type response:(void (^)(id responseObject,NSError *error))handle
{
id<UMComMessageDelegate> messageDelegate = [self sharedInstance].messageDelegate;
if (messageDelegate && [messageDelegate respondsToSelector:@selector(addAlias:type:response:)]) {
[messageDelegate addAlias:name type:type response:^(id responseObject, NSError *error) {
SafeCompletionDataAndError(handle, responseObject, error);
}];
}
}
+ (void)removeAlias:(NSString *)name type:(NSString *)type response:(void (^)(id, NSError *))handle
{
id<UMComMessageDelegate> messageDelegate = [self sharedInstance].messageDelegate;
if (messageDelegate && [messageDelegate respondsToSelector:@selector(removeAlias:type:response:)]) {
[messageDelegate removeAlias:name type:type response:handle];
}
}
+ (void)handleUserInfo:(NSDictionary *)userInfo
{
// UIViewController *controller = nil;
NSString *feed_id = nil;
NSString *comment_id = nil;
UIViewController *rootViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
UIViewController * presentedViewController = rootViewController.presentedViewController;
if (presentedViewController) {
while (presentedViewController) {
if (presentedViewController.presentedViewController){
presentedViewController = presentedViewController.presentedViewController;
} else {
break;
}
}
} else {
presentedViewController = rootViewController;
}
NSString *controllerName = [userInfo valueForKey:@"umeng_comm_afteropen_controller"];
if ([controllerName isEqualToString:@"UMComFeedDetailViewController"]) {
if ([userInfo valueForKey:@"feed_id"]) {
feed_id = [userInfo valueForKey:@"feed_id"];
}
if ([userInfo valueForKey:@"comment_id"]){
comment_id = [userInfo valueForKey:@"comment_id"];
}
[self handleExtraInfo:userInfo];
if ([feed_id isKindOfClass:[NSString class]]) {
[UMComLoginManager performLogin:presentedViewController completion:^(id responseObject, NSError *error) {
if (!error) {
NSMutableDictionary * extraDic = [NSMutableDictionary dictionary];
if (feed_id) {
[extraDic setValue:feed_id forKey:@"feed_id"];
}
if (comment_id) {
[extraDic setValue:comment_id forKey:@"comment_id"];
}
UIViewController *viewController = [self getDetailVCWithFeedId:feed_id ExtraDict:extraDic];
if (viewController) {
UMComNavigationController *feedDetailNav = [[UMComNavigationController alloc] initWithRootViewController:viewController];
[presentedViewController presentViewController:feedDetailNav animated:YES completion:nil];
}
else
{
Class UMComRemoteNoticeViewController = NSClassFromString(@"UMComRemoteNoticeViewController");
UIViewController *remoteNoticeViewController = [[UMComRemoteNoticeViewController alloc] init];
UMComNavigationController *feedDetailNav = [[UMComNavigationController alloc] initWithRootViewController:remoteNoticeViewController];
[presentedViewController presentViewController:feedDetailNav animated:YES completion:nil];
}
}
}];
}
}
else if ([controllerName isEqualToString:@"UMComRemoteNoticeViewController"]){
[UMComLoginManager performLogin:presentedViewController completion:^(id responseObject, NSError *error) {
if (!error) {
Class UMComRemoteNoticeViewController = NSClassFromString(@"UMComRemoteNoticeViewController");
UIViewController *remoteNoticeViewController = [[UMComRemoteNoticeViewController alloc] init];
UMComNavigationController *feedDetailNav = [[UMComNavigationController alloc] initWithRootViewController:remoteNoticeViewController];
[presentedViewController presentViewController:feedDetailNav animated:YES completion:nil];
}
}];
}
}
+ (UIViewController *)getDetailVCWithFeedId:(NSString *)feedId ExtraDict:(NSDictionary *)extraDic
{
UIViewController *viewController = nil;
if (NSClassFromString(@"UMComPostContentViewController")) {
Class cls = NSClassFromString(@"UMComPostContentViewController");
UIViewController *vc = [cls alloc];
SEL sel = NSSelectorFromString(@"initWithFeed:viewExtra:");
if ([vc respondsToSelector:sel]) {
[vc performSelector:sel withObject:feedId withObject:extraDic];
}
viewController = vc;
} else
if(NSClassFromString(@"UMComFeedDetailViewController")) {
Class cls = NSClassFromString(@"UMComFeedDetailViewController");
UIViewController *vc = [cls alloc];
SEL sel = NSSelectorFromString(@"initWithFeed:viewExtra:");
if ([vc respondsToSelector:sel]) {
[vc performSelector:sel withObject:feedId withObject:extraDic];
}
viewController = vc;
}
return viewController;
}
+ (void)handleExtraInfo:(NSDictionary *)userInfo
{
}
+ (void)remoteNotificationForEnterDetailView:(UMComPushDetailViewBlock)handle
{
[self sharedInstance].pushViewBlock = handle;
}
@end
@@ -0,0 +1,61 @@
//
// UMComLoginDelegate.h
// UMCommunity
//
// Created by Gavin Ye on 11/11/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComResouceDefines.h"
@class UMComFeed;
@protocol UMComShareDelegate <NSObject>
@optional
/**
设置自定义登录的Appkey
*/
- (void)setAppKey:(NSString *)appKey;
/**
自定义登录或者自定义分享处理URL地址
@param 应用回传的URL地址
@returns 处理结果
*/
- (BOOL)handleOpenURL:(NSURL *)url;
/**
点击某个分享平台之后的回调方法
@param platformIndex 分享平台名所在的位置
@param feed 分享的当条Feed
@param viewController 当前ViewController
*/
- (void)didSelectPlatformAtIndex:(NSInteger)platformIndex
feed:(UMComFeed *)feed
viewController:(UIViewController *)viewControlller;
/**
* 分享平台icon
*
* @return 分享平台icon数组
*/
- (NSArray *)sharePlatformIcons;
/**
* 分享平台title
*
* @return 分享平台title数组
*/
- (NSArray *)sharePlatformNames;
@end
@@ -0,0 +1,35 @@
//
// UMComLoginManager.h
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "UMComLoginUser.h"
#import "UMComShareDelegate.h"
@interface UMComShareManager : NSObject
/********************UMComFirstTimeHandelerDelegate*******************/
/**
获取处理登录完后的逻辑的实现代理
*/
@property (nonatomic, strong) id<UMComShareDelegate> shareHadleDelegate;
+ (UMComShareManager *)shareInstance;
/**
处理SSO跳转回来之后的url
*/
+ (BOOL)handleOpenURL:(NSURL *)url;
@end
@@ -0,0 +1,69 @@
//
// UMComLoginManager.m
// UMCommunity
//
// Created by Gavin Ye on 8/25/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import "UMComShareManager.h"
#import "UMComShareDelegate.h"
#import <UMCommunitySDK/UMCommunitySDK.h>
@interface UMComShareManager ()
@end
@implementation UMComShareManager
static UMComShareManager *_instance = nil;
+ (void)load
{
[self shareInstance];
}
+ (UMComShareManager *)shareInstance {
@synchronized (self) {
if (_instance == nil) {
_instance = [[UMComShareManager alloc] init];
}
}
return _instance;
}
- (id)init
{
self = [super init];
if (self) {
Class delegateClass = NSClassFromString(@"UMComShareDelegateHandler");
self.shareHadleDelegate = [[delegateClass alloc] init];
[self registerNotifications];
}
return self;
}
- (void)registerNotifications
{
__weak typeof(self) ws = self;
[[NSNotificationCenter defaultCenter] addObserverForName:kUMComUpdateAppKeyNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[ws setAppKey:[UMCommunitySDK appKey]];
}];
}
- (void)setAppKey:(NSString *)appKey
{
if ([self.shareHadleDelegate respondsToSelector:@selector(setAppKey:)]) {
[self.shareHadleDelegate setAppKey:appKey];
}
}
+ (BOOL)handleOpenURL:(NSURL *)url
{
if ([[self shareInstance].shareHadleDelegate respondsToSelector:@selector(handleOpenURL:)]) {
return [[self shareInstance].shareHadleDelegate handleOpenURL:url];
}
return NO;
}
@end