@@ -25,8 +25,8 @@ @interface CodingShareView ()<UMSocialUIDelegate>
2525@property (strong , nonatomic ) UIButton *dismissBtn;
2626@property (strong , nonatomic ) UIScrollView *itemsScrollView;
2727
28- @property (strong , nonatomic ) NSObject *objToShare;
2928@property (strong , nonatomic ) NSArray *shareSnsValues;
29+ @property (weak , nonatomic ) NSObject *objToShare;
3030@end
3131
3232@implementation CodingShareView
@@ -158,8 +158,8 @@ + (NSDictionary *)snsNameDict{
158158
159159}
160160
161- + (void )showShareViewWithTweet : (Tweet *)curTweet {
162- [[self sharedInstance ] showShareViewWithTweet: curTweet ];
161+ + (void )showShareViewWithObj : (Tweet *)curObj {
162+ [[self sharedInstance ] showShareViewWithObj: curObj ];
163163}
164164
165165+(NSArray *)supportSnsValues {
@@ -198,8 +198,8 @@ +(BOOL)p_canOpen:(NSString*)url{
198198 return [[UIApplication sharedApplication ] canOpenURL: [NSURL URLWithString: url]];
199199}
200200
201- - (void )showShareViewWithTweet : (Tweet *)curTweet {
202- self.objToShare = curTweet ;
201+ - (void )showShareViewWithObj : ( NSObject *)curObj {
202+ self.objToShare = curObj ;
203203 [self p_show ];
204204}
205205
@@ -245,15 +245,6 @@ - (void)p_dismissWithCompletionBlock:(void (^)(void))completionBlock{
245245 }
246246 }];
247247}
248- - (void )p_checkTitle {
249- NSString *title;
250- if ([_objToShare isKindOfClass: [Tweet class ]]) {
251- title = @" 冒泡分享到" ;
252- }else {
253- title = @" 分享到" ;
254- }
255- _titleL.text = title;
256- }
257248- (void )p_checkShareSnsValues {
258249 self.shareSnsValues = [CodingShareView supportSnsValues ];
259250}
@@ -274,55 +265,11 @@ - (void)p_doShareToSnsName:(NSString *)snsName{
274265 }else if ([snsName isEqualToString: @" coding" ]){
275266 PrivateMessage *curMsg = [PrivateMessage privateMessageWithObj: [self p_shareLinkStr ] andFriend: nil ];
276267 [self willTranspondMessage: curMsg];
277- // }else if ([snsName isEqualToString:@"sina"]){
278- // NSString *shareTitle, *shareText, *shareTail;
279- // shareTitle = [NSString stringWithFormat:@"「%@」", [self p_shareTitle]];
280- // shareText = [self p_shareText];
281- // shareTail = [NSString stringWithFormat:@"%@(分享自@Coding)", [self p_shareLinkStr]];
282- // NSInteger maxShareLength = 140;
283- // NSInteger maxTextLength = maxShareLength - shareTitle.length - shareTail.length;
284- // if (shareText.length > maxTextLength) {
285- // shareText = [shareText stringByReplacingCharactersInRange:NSMakeRange(maxTextLength - 3, shareText.length - (maxTextLength - 3)) withString:@"..."];
286- // }
287- // NSString *shareContent = [NSString stringWithFormat:@"%@%@%@", shareTitle, shareText, shareTail];
288- // [NSObject showStatusBarQueryStr:@"正在分享到新浪微博"];
289- //
290- // UMSocialUrlResource *urlResource = nil;
291- // NSString *imageUrl = [self p_imageUrlSquare:NO];
292- // if (imageUrl.length > 0) {
293- // urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:imageUrl];
294- // }
295- // [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:shareContent image:nil location:nil urlResource:urlResource presentedController:[BaseViewController presentingVC] completion:^(UMSocialResponseEntity *response) {
296- // if (response.responseCode == UMSResponseCodeSuccess) {
297- // [NSObject showStatusBarSuccessStr:@"分享成功"];
298- // }else{
299- // [NSObject showStatusBarErrorStr:@"分享失败"];
300- // }
301- // }];
302268 }else if ([snsName isEqualToString: @" evernote" ]){
303- ENNote *noteToSave = [ENNote new ];
304- noteToSave.title = [self p_shareTitle ];
305- NSString *htmlStr;
306- if ([_objToShare respondsToSelector: NSSelectorFromString (@" htmlMedia" )]) {
307- HtmlMedia *htmlMedia = [_objToShare valueForKey: @" htmlMedia" ];
308- htmlStr = htmlMedia.contentOrigional ;
309- }else {
310- htmlStr = [self p_shareText ];
311- }
312- htmlStr = [htmlStr stringByAppendingFormat: @" <p><a href=\" %@ \" >冒泡原始链接</a></p>" , [self p_shareLinkStr ]];
313- noteToSave.content = [ENNoteContent noteContentWithSanitizedHTML: htmlStr];
314-
315- if (![[ENSession sharedSession ] isAuthenticated ]) {
316- [[ENSession sharedSession ] authenticateWithViewController: [BaseViewController presentingVC ] preferRegistration: NO completion: ^(NSError *authenticateError) {
317- if (!authenticateError) {
318- [self p_uploadENNote: noteToSave];
319- }else if (authenticateError.code != ENErrorCodeCancelled){
320- [NSObject showHudTipStr: @" 授权失败" ];
321- }
322- }];
323- }else {
324- [self p_uploadENNote: noteToSave];
325- }
269+ __weak typeof (self) weakSelf = self;
270+ [self p_shareENNoteWithompletion: ^(ENNote *note) {
271+ [weakSelf p_willUploadENNote: note];
272+ }];
326273 }else {
327274 [[UMSocialControllerService defaultControllerService ] setSocialUIDelegate: self ];
328275 UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName: snsName];
@@ -331,8 +278,24 @@ - (void)p_doShareToSnsName:(NSString *)snsName{
331278 }
332279 }
333280}
334-
335- - (void )p_uploadENNote : (ENNote *)noteToSave {
281+ - (void )p_willUploadENNote : (ENNote *)noteToSave {
282+ if (!noteToSave) {
283+ [NSObject showHudTipStr: @" 不支持保存到印象笔记" ];
284+ return ;
285+ }
286+ if (![[ENSession sharedSession ] isAuthenticated ]) {
287+ [[ENSession sharedSession ] authenticateWithViewController: [BaseViewController presentingVC ] preferRegistration: NO completion: ^(NSError *authenticateError) {
288+ if (!authenticateError) {
289+ [self p_doUploadENNote: noteToSave];
290+ }else if (authenticateError.code != ENErrorCodeCancelled){
291+ [NSObject showHudTipStr: @" 授权失败" ];
292+ }
293+ }];
294+ }else {
295+ [self p_doUploadENNote: noteToSave];
296+ }
297+ }
298+ - (void )p_doUploadENNote : (ENNote *)noteToSave {
336299 if (noteToSave) {
337300 [NSObject showStatusBarQueryStr: @" 正在保存到印象笔记" ];
338301 [[ENSession sharedSession ] uploadNote: noteToSave notebook: nil completion: ^(ENNoteRef *noteRef, NSError *uploadNoteError) {
@@ -344,11 +307,25 @@ - (void)p_uploadENNote:(ENNote *)noteToSave{
344307 }];
345308 }
346309}
310+ #pragma mark objToShare
311+ - (void )p_checkTitle {
312+ NSString *title;
313+ if ([_objToShare isKindOfClass: [Tweet class ]]) {
314+ title = @" 冒泡分享到" ;
315+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
316+ title = @" 链接分享到" ;
317+ }else {
318+ title = @" 分享到" ;
319+ }
320+ _titleL.text = title;
321+ }
347322
348323- (NSString *)p_shareLinkStr {
349324 NSString *linkStr;
350325 if ([_objToShare isKindOfClass: [Tweet class ]]) {
351326 linkStr = [(Tweet *)_objToShare toShareLinkStr ];
327+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
328+ linkStr = [(UIWebView *)_objToShare request ].URL .absoluteString ;
352329 }else {
353330 linkStr = [NSObject baseURLStr ];
354331 }
@@ -358,6 +335,8 @@ - (NSString *)p_shareTitle{
358335 NSString *title;
359336 if ([_objToShare isKindOfClass: [Tweet class ]]) {
360337 title = [NSString stringWithFormat: @" %@ 的冒泡" , [(Tweet *)_objToShare owner ].name];
338+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
339+ title = @" Coding 链接" ;
361340 }else {
362341 title = @" Coding" ;
363342 }
@@ -367,6 +346,8 @@ - (NSString *)p_shareText{
367346 NSString *text;
368347 if ([_objToShare isKindOfClass: [Tweet class ]]) {
369348 text = [(Tweet *)_objToShare content ];
349+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
350+ text =[(UIWebView *)_objToShare stringByEvaluatingJavaScriptFromString: @" document.title" ];
370351 }else {
371352 text = @" Coding 让开发更简单!" ;
372353 }
@@ -391,6 +372,20 @@ - (NSString *)p_imageUrlSquare:(BOOL)needSquare{
391372 }
392373 return imageUrl;
393374}
375+ - (void )p_shareENNoteWithompletion : (ENNotePopulateFromWebViewCompletionHandler)completion {
376+ if ([_objToShare respondsToSelector: NSSelectorFromString (@" htmlMedia" )]) {
377+ ENNote *note = [ENNote new ];
378+ note.title = [self p_shareTitle ];
379+ NSString *htmlStr;
380+ HtmlMedia *htmlMedia = [_objToShare valueForKey: @" htmlMedia" ];
381+ htmlStr = htmlMedia.contentOrigional ;
382+ htmlStr = [htmlStr stringByAppendingFormat: @" <p><a href=\" %@ \" >原始链接</a></p>" , [self p_shareLinkStr ]];
383+ note.content = [ENNoteContent noteContentWithSanitizedHTML: htmlStr];
384+ completion (note);
385+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
386+ [ENNote populateNoteFromWebView: (UIWebView *)_objToShare completion: completion];
387+ }
388+ }
394389#pragma mark TranspondMessage
395390
396391- (void )willTranspondMessage : (PrivateMessage *)message {
@@ -415,7 +410,7 @@ -(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)respon
415410 if (response.responseCode == UMSResponseCodeSuccess){
416411 NSString *snsName = [[response.data allKeys ] firstObject ];
417412 NSLog (@" share to sns name is %@ " ,snsName);
418- [self performSelector: @selector (showStatusBarSuccessStr: ) withObject: @" 分享成功" afterDelay: 0.3 ];
413+ [NSObject performSelector: @selector (showStatusBarSuccessStr: ) withObject: @" 分享成功" afterDelay: 0.3 ];
419414 }
420415}
421416
0 commit comments