@@ -25,8 +25,8 @@ @interface CodingShareView ()<UMSocialUIDelegate>
25
25
@property (strong , nonatomic ) UIButton *dismissBtn;
26
26
@property (strong , nonatomic ) UIScrollView *itemsScrollView;
27
27
28
- @property (strong , nonatomic ) NSObject *objToShare;
29
28
@property (strong , nonatomic ) NSArray *shareSnsValues;
29
+ @property (weak , nonatomic ) NSObject *objToShare;
30
30
@end
31
31
32
32
@implementation CodingShareView
@@ -158,8 +158,8 @@ + (NSDictionary *)snsNameDict{
158
158
159
159
}
160
160
161
- + (void )showShareViewWithTweet : (Tweet *)curTweet {
162
- [[self sharedInstance ] showShareViewWithTweet: curTweet ];
161
+ + (void )showShareViewWithObj : (Tweet *)curObj {
162
+ [[self sharedInstance ] showShareViewWithObj: curObj ];
163
163
}
164
164
165
165
+(NSArray *)supportSnsValues {
@@ -198,8 +198,8 @@ +(BOOL)p_canOpen:(NSString*)url{
198
198
return [[UIApplication sharedApplication ] canOpenURL: [NSURL URLWithString: url]];
199
199
}
200
200
201
- - (void )showShareViewWithTweet : (Tweet *)curTweet {
202
- self.objToShare = curTweet ;
201
+ - (void )showShareViewWithObj : ( NSObject *)curObj {
202
+ self.objToShare = curObj ;
203
203
[self p_show ];
204
204
}
205
205
@@ -245,15 +245,6 @@ - (void)p_dismissWithCompletionBlock:(void (^)(void))completionBlock{
245
245
}
246
246
}];
247
247
}
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
- }
257
248
- (void )p_checkShareSnsValues {
258
249
self.shareSnsValues = [CodingShareView supportSnsValues ];
259
250
}
@@ -274,55 +265,11 @@ - (void)p_doShareToSnsName:(NSString *)snsName{
274
265
}else if ([snsName isEqualToString: @" coding" ]){
275
266
PrivateMessage *curMsg = [PrivateMessage privateMessageWithObj: [self p_shareLinkStr ] andFriend: nil ];
276
267
[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
- // }];
302
268
}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
+ }];
326
273
}else {
327
274
[[UMSocialControllerService defaultControllerService ] setSocialUIDelegate: self ];
328
275
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName: snsName];
@@ -331,8 +278,24 @@ - (void)p_doShareToSnsName:(NSString *)snsName{
331
278
}
332
279
}
333
280
}
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 {
336
299
if (noteToSave) {
337
300
[NSObject showStatusBarQueryStr: @" 正在保存到印象笔记" ];
338
301
[[ENSession sharedSession ] uploadNote: noteToSave notebook: nil completion: ^(ENNoteRef *noteRef, NSError *uploadNoteError) {
@@ -344,11 +307,25 @@ - (void)p_uploadENNote:(ENNote *)noteToSave{
344
307
}];
345
308
}
346
309
}
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
+ }
347
322
348
323
- (NSString *)p_shareLinkStr {
349
324
NSString *linkStr;
350
325
if ([_objToShare isKindOfClass: [Tweet class ]]) {
351
326
linkStr = [(Tweet *)_objToShare toShareLinkStr ];
327
+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
328
+ linkStr = [(UIWebView *)_objToShare request ].URL .absoluteString ;
352
329
}else {
353
330
linkStr = [NSObject baseURLStr ];
354
331
}
@@ -358,6 +335,8 @@ - (NSString *)p_shareTitle{
358
335
NSString *title;
359
336
if ([_objToShare isKindOfClass: [Tweet class ]]) {
360
337
title = [NSString stringWithFormat: @" %@ 的冒泡" , [(Tweet *)_objToShare owner ].name];
338
+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
339
+ title = @" Coding 链接" ;
361
340
}else {
362
341
title = @" Coding" ;
363
342
}
@@ -367,6 +346,8 @@ - (NSString *)p_shareText{
367
346
NSString *text;
368
347
if ([_objToShare isKindOfClass: [Tweet class ]]) {
369
348
text = [(Tweet *)_objToShare content ];
349
+ }else if ([_objToShare isKindOfClass: [UIWebView class ]]){
350
+ text =[(UIWebView *)_objToShare stringByEvaluatingJavaScriptFromString: @" document.title" ];
370
351
}else {
371
352
text = @" Coding 让开发更简单!" ;
372
353
}
@@ -391,6 +372,20 @@ - (NSString *)p_imageUrlSquare:(BOOL)needSquare{
391
372
}
392
373
return imageUrl;
393
374
}
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
+ }
394
389
#pragma mark TranspondMessage
395
390
396
391
- (void )willTranspondMessage : (PrivateMessage *)message {
@@ -415,7 +410,7 @@ -(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)respon
415
410
if (response.responseCode == UMSResponseCodeSuccess){
416
411
NSString *snsName = [[response.data allKeys ] firstObject ];
417
412
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 ];
419
414
}
420
415
}
421
416
0 commit comments