iOS5 - sharekit for twitter issue

孤人 提交于 2019-12-03 03:52:57

Edit:

Fix Issue #254 - IOS 5 Cancel Button Fix for issue https://github.com/ideashower/ShareKit/issues/254.

In iOS 5, a modally presented view controller has a nil parentViewController, and instead the presenter is presentingViewController. Changed the attempts to dismiss the view using the parentViewController to check for the iOS 5 selector, and used it if available.

So get the latest ShareKit.

Edit 2:

I recommend to use TWTweetComposeViewController if the device has iOS 5.

Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

     if (TWTweetComposeViewControllerClass != nil) {
          if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
              UIViewController *twitterViewController = [[TWTweetComposeViewControllerClass alloc] init];

              [twitterViewController performSelector:@selector(setInitialText:) 
                                          withObject:NSLocalizedString(@"TwitterMessage", @"")];
              [twitterViewController performSelector:@selector(addURL:) 
                                          withObject:url];

               [twitterViewController performSelector:@selector(addImage:) 
                                           withObject:[UIImage imageNamed:@"yourImage.png"]];
                [self.navigationController presentModalViewController:twitterViewController animated:YES];
                [twitterViewController release];
                }
            } else {
                [SHK flushOfflineQueue];
                SHKItem *item = [SHKItem URL:url title:NSLocalizedString(@"TwitterMessage", @"")];

                // Get the ShareKit action sheet
                SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

                // Display the action sheet
                [actionSheet showInView:[self.view superview].window];
            }

Add in your h file

#if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#endif

And add the Twitter framework and Accounts as optional Libraries.

Find Alex Terente's Answer in wiki also.

Edit1:

Fix Issue #254 - IOS 5 Cancel Button Fix for issue https://github.com/ideashower/ShareKit/issues/254. In iOS 5, a modally presented view controller has a nil parentViewController, and instead the presenter is presentingViewController. Changed the attempts to dismiss the view using the parentViewController to check for the iOS 5 selector, and used it if available. So get the latest ShareKit.

Edit 2: I recommend to use TWTweetComposeViewController if the device has iOS 5.

Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

     if (TWTweetComposeViewControllerClass != nil) {
          if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
              UIViewController *twitterViewController = [[TWTweetComposeViewControllerClass alloc] init];

              [twitterViewController performSelector:@selector(setInitialText:) 
                                          withObject:NSLocalizedString(@"TwitterMessage", @"")];
              [twitterViewController performSelector:@selector(addURL:) 
                                          withObject:url];

               [twitterViewController performSelector:@selector(addImage:) 
                                           withObject:[UIImage imageNamed:@"yourImage.png"]];
                [self.navigationController presentModalViewController:twitterViewController animated:YES];
                [twitterViewController release];
                }
            } else {
                [SHK flushOfflineQueue];
                SHKItem *item = [SHKItem URL:url title:NSLocalizedString(@"TwitterMessage", @"")];

                // Get the ShareKit action sheet
                SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

                // Display the action sheet
                [actionSheet showInView:[self.view superview].window];
            }

Add in your h file

#if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#endif

And add the Twitter framework and Accounts as optional Libraries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!