Skip to content

Commit

Permalink
Merge branch 'master' of github.com:doubleencore/DETweetComposeViewCo…
Browse files Browse the repository at this point in the history
…ntroller

Conflicts:
	DETweetComposeViewController/DETweetPoster.m
	DETweetComposeViewController/UIApplication+DETweetComposeViewController.h
	DETweetComposeViewController/UIApplication+DETweetComposeViewController.m
	DETweetComposeViewController/UIDevice+DETweetComposeViewController.h
	DETweetComposeViewController/UIDevice+DETweetComposeViewController.m
  • Loading branch information
Dave Batton authored and Dave Batton committed Dec 21, 2011
2 parents de3cf58 + d36c7aa commit 09dc722
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 42 deletions.
23 changes: 11 additions & 12 deletions DETweetComposeViewController/DETweetComposeViewController.m
Expand Up @@ -23,7 +23,6 @@
#import "DETweetGradientView.h"
#import "OAuth.h"
#import "OAuth+DEExtensions.h"
#import "UIApplication+DETweetComposeViewController.h"
#import "UIDevice+DETweetComposeViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <Accounts/Accounts.h>
Expand Down Expand Up @@ -112,7 +111,7 @@ @implementation DETweetComposeViewController

+ (BOOL)canAccessTwitterAccounts
{
if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
ACAccountStore *accountStore = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

Expand All @@ -138,7 +137,7 @@ + (BOOL)canSendTweet
{
BOOL canSendTweet = NO;

if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
if ([[self class] canAccessTwitterAccounts]) {
ACAccountStore *accountStore = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
Expand Down Expand Up @@ -280,7 +279,7 @@ - (void)viewDidLoad
((UIImageView *)obj).layer.masksToBounds = YES;
}];

if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
self.textView.keyboardType = UIKeyboardTypeTwitter;
}

Expand All @@ -297,7 +296,7 @@ - (void)viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];

// Now let's fade in a gradient view over the presenting view.
UIView *presentingView = [UIApplication isIOS5] ? self.presentingViewController.view : self.parentViewController.view;
UIView *presentingView = [UIDevice de_isIOS5] ? self.presentingViewController.view : self.parentViewController.view;
CGRect frame = CGRectMake(0.0f,
0.0f,
presentingView.bounds.size.width,
Expand All @@ -319,7 +318,7 @@ - (void)viewWillAppear:(BOOL)animated
[self updateFramesForOrientation:self.interfaceOrientation];

// Make sure we have a Twitter account to work with.
if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
if ([[self class] canAccessTwitterAccounts] == NO) {
[self performSelector:@selector(dismissModalViewControllerAnimated:) withObject:self afterDelay:1.0f];
}
Expand All @@ -333,7 +332,7 @@ - (void)viewWillAppear:(BOOL)animated
// Like TWTweetComposeViewController, we'll let the user change the account only if
// we're in portrait orientation on iPhone. iPad can do it in any orientation.
if ([[DETweetPoster accounts] count] > 1
&& ([UIDevice isPad] || UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) ) {
&& ([UIDevice de_isPad] || UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) ) {
self.textView.accountName = ((ACAccount *)self.twitterAccount).accountDescription;
}
else {
Expand All @@ -360,7 +359,7 @@ - (void)viewWillDisappear:(BOOL)animated

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
else {
Expand Down Expand Up @@ -537,7 +536,7 @@ - (void)updateFramesForOrientation:(UIInterfaceOrientation)interfaceOrientation
CGFloat titleLabelFontSize, titleLabelTop;
CGFloat characterCountLeft, characterCountTop;

if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
cardWidth = CGRectGetWidth(self.view.bounds) - 10.0f;
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
cardTop = 25.0f;
Expand Down Expand Up @@ -620,7 +619,7 @@ - (void)updateFramesForOrientation:(UIInterfaceOrientation)interfaceOrientation

characterCountLeft = CGRectGetWidth(self.cardView.frame) - CGRectGetWidth(self.characterCountLabel.frame) - 12.0f;
characterCountTop = CGRectGetHeight(self.cardView.frame) - CGRectGetHeight(self.characterCountLabel.frame) - 8.0f;
if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
characterCountTop -= 5.0f;
if ([self attachmentsCount] > 0) {
Expand Down Expand Up @@ -723,7 +722,7 @@ - (void)selectTwitterAccount
// If one is already selected, makes sure it's still valid.
// If not, another is picked.
{
if ([UIApplication isIOS5] == NO) {
if ([UIDevice de_isIOS5] == NO) {
return;
}

Expand Down Expand Up @@ -776,7 +775,7 @@ - (void)displayNoTwitterAccountsAlert

- (void)presentAccountPicker
{
if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
if (self.accountPickerView == nil) {
self.accountPickerView = [[[UIPickerView alloc] init] autorelease];
CGRect frame = self.accountPickerView.frame;
Expand Down
6 changes: 3 additions & 3 deletions DETweetComposeViewController/DETweetPoster.m
Expand Up @@ -21,7 +21,7 @@
#import "OAuth+DEExtensions.h"
#import "OAuthConsumerCredentials.h"
#import "NSString+URLEncoding.h"
#import "UIApplication+DETweetComposeViewController.h"
#import "UIDevice+DETweetComposeViewController.h"
#import <Accounts/Accounts.h>
#import <Twitter/TWRequest.h>

Expand Down Expand Up @@ -72,7 +72,7 @@ - (void)postTweet:(NSString *)tweetText withImages:(NSArray *)images
// Posts the tweet with the first available account on iOS 5.
{
id account = nil; // An ACAccount. But that didn't exist on iOS 4.
if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
NSArray *twitterAccounts = [[self class] accounts];
if ([twitterAccounts count] > 0) {
account = [twitterAccounts objectAtIndex:0];
Expand All @@ -91,7 +91,7 @@ - (void)postTweet:(NSString *)tweetText withImages:(NSArray *)images
- (void)postTweet:(NSString *)tweetText withImages:(NSArray *)images fromAccount:(id)account
{
NSURLRequest *postRequest = nil;
if ([UIApplication isIOS5] && account != nil) {
if ([UIDevice de_isIOS5] && account != nil) {
TWRequest *twRequest = nil;
if ([images count] > 0) {
twRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:twitterPostWithImagesURLString]
Expand Down
Expand Up @@ -20,8 +20,9 @@

@interface UIDevice (DETweetComposeViewController)

+ (BOOL)isPad;
+ (BOOL)isPhone;
+ (BOOL)isRetinaDisplay;
+ (BOOL)de_isIOS5;
+ (BOOL)de_isPad;
+ (BOOL)de_isPhone;
+ (BOOL)de_isRetinaDisplay;

@end
Expand Up @@ -21,20 +21,25 @@

@implementation UIDevice (DETweetComposeViewController)

+ (BOOL)de_isIOS5
{
return (NSClassFromString(@"NSJSONSerialization") != nil);
}


+ (BOOL)isPad
+ (BOOL)de_isPad
{
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? YES : NO;
}


+ (BOOL)isPhone
+ (BOOL)de_isPhone
{
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ? YES : NO;
}


+ (BOOL)isRetinaDisplay
+ (BOOL)de_isRetinaDisplay
{
UIScreen* screen = [UIScreen mainScreen];
if ([screen respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
Expand Down
8 changes: 2 additions & 6 deletions DETweeter.xcodeproj/project.pbxproj
Expand Up @@ -35,7 +35,6 @@
697FE2DA149040AF0045B8C7 /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 697FE2D9149040AF0045B8C7 /* Accounts.framework */; };
699A29BB1459B3960046B260 /* DETweetPoster.m in Sources */ = {isa = PBXBuildFile; fileRef = 699A29BA1459B3960046B260 /* DETweetPoster.m */; };
69E70E8A1484BAD5004A66CA /* DEHTTPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E70E891484BAD5004A66CA /* DEHTTPRequest.m */; };
69EC1CC114885748002DB78F /* UIApplication+DETweetComposeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69EC1CC014885748002DB78F /* UIApplication+DETweetComposeViewController.m */; };
69ED66BA14908CC4009602F5 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 69ED66B914908CC4009602F5 /* Settings.bundle */; };
69F126411489A81C00343C3D /* YawkeyBusinessDog.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 69F126401489A81C00343C3D /* YawkeyBusinessDog.jpg */; };
B60F06991486F0C000CE3BD6 /* icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B60F06981486F0C000CE3BD6 /* icon@2x.png */; };
Expand Down Expand Up @@ -139,8 +138,6 @@
699A29BA1459B3960046B260 /* DETweetPoster.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DETweetPoster.m; path = ../DETweetComposeViewController/DETweetPoster.m; sourceTree = "<group>"; };
69E70E881484BAD5004A66CA /* DEHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DEHTTPRequest.h; sourceTree = "<group>"; };
69E70E891484BAD5004A66CA /* DEHTTPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DEHTTPRequest.m; sourceTree = "<group>"; };
69EC1CBF14885748002DB78F /* UIApplication+DETweetComposeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIApplication+DETweetComposeViewController.h"; path = "DETweetComposeViewController/UIApplication+DETweetComposeViewController.h"; sourceTree = SOURCE_ROOT; };
69EC1CC014885748002DB78F /* UIApplication+DETweetComposeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIApplication+DETweetComposeViewController.m"; path = "DETweetComposeViewController/UIApplication+DETweetComposeViewController.m"; sourceTree = SOURCE_ROOT; };
69ED66B914908CC4009602F5 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
69F126401489A81C00343C3D /* YawkeyBusinessDog.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = YawkeyBusinessDog.jpg; sourceTree = "<group>"; };
7B821E4A14928C35006FDD64 /* OAuthConsumerCredentials.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OAuthConsumerCredentials.h; path = "DETweeter/unofficial-twitter-sdk/unoffical-twitter-sdk/OAuth/OAuthConsumerCredentials.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -416,8 +413,6 @@
60C6B2ED1471D47D0090278C /* OAuth+DEExtensions.m */,
60C6B2E81471CBD90090278C /* OAuth+DEUserDefaults.h */,
60C6B2EA1471CBEE0090278C /* OAuth+DEUserDefaults.m */,
69EC1CBF14885748002DB78F /* UIApplication+DETweetComposeViewController.h */,
69EC1CC014885748002DB78F /* UIApplication+DETweetComposeViewController.m */,
697FE2CD14903C750045B8C7 /* UIDevice+DETweetComposeViewController.h */,
697FE2CE14903C750045B8C7 /* UIDevice+DETweetComposeViewController.m */,
B6B6CCF214586015005B93A1 /* Images */,
Expand Down Expand Up @@ -578,7 +573,6 @@
B69AB9B414869A5C00652DDF /* DETweetGradientView.m in Sources */,
B69C605A14894F4D00A18C1B /* DERuledView.m in Sources */,
B68527C0148F1DB900B18D5D /* DEEmbossedLabel.m in Sources */,
69EC1CC114885748002DB78F /* UIApplication+DETweetComposeViewController.m in Sources */,
697FE2CF14903C750045B8C7 /* UIDevice+DETweetComposeViewController.m in Sources */,
B68728AB14A10C0200593E39 /* DETweetAccountSelectorViewController.m in Sources */,
);
Expand Down Expand Up @@ -638,6 +632,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
RUN_CLANG_STATIC_ANALYZER = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -664,6 +659,7 @@
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PROVISIONING_PROFILE = "8415AEA1-CA31-47C4-B8C4-F353C9FE0435";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "8415AEA1-CA31-47C4-B8C4-F353C9FE0435";
RUN_CLANG_STATIC_ANALYZER = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand Down
2 changes: 1 addition & 1 deletion DETweeter/DEAppDelegate.m
Expand Up @@ -36,7 +36,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
self.viewController = [[[DEViewController alloc] initWithNibName:@"DEViewController_iPhone" bundle:nil] autorelease];
}
else {
Expand Down
22 changes: 10 additions & 12 deletions DETweeter/DEViewController.m
Expand Up @@ -11,7 +11,6 @@
#import "OAuth+DEExtensions.h"
#import "OAuthConsumerCredentials.h"
#import "UIDevice+DETweetComposeViewController.h"
#import "UIApplication+DETweetComposeViewController.h"
#import <Twitter/Twitter.h>


Expand Down Expand Up @@ -93,7 +92,7 @@ - (void)viewDidLoad

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
else {
Expand Down Expand Up @@ -130,7 +129,7 @@ - (void)updateFramesForOrientation:(UIInterfaceOrientation)interfaceOrientation
{
CGRect frame = self.buttonView.frame;
frame.origin.x = trunc((self.view.bounds.size.width - frame.size.width) / 2);
if ([UIDevice isPhone]) {
if ([UIDevice de_isPhone]) {
frame.origin.y = UIInterfaceOrientationIsPortrait(interfaceOrientation) ? 306.0f : 210.0f;
}
else {
Expand Down Expand Up @@ -192,22 +191,21 @@ - (void)tweetThem

- (void)addTweetContent:(id)tcvc
{
BOOL accepted; // Just interesting to watch in the debugger.
accepted = [tcvc addImage:[UIImage imageNamed:@"YawkeyBusinessDog.jpg"]];
accepted = [tcvc addImage:[UIImage imageNamed:@"YawkeyCleanTeeth.jpg"]]; // This one won't actually work. Only one image per tweet allowed currently by Twitter.
accepted = [tcvc addURL:[NSURL URLWithString:@"http://www.DoubleEncore.com/"]];
accepted = [tcvc addURL:[NSURL URLWithString:@"http://www.apple.com/ios/features.html#twitter"]];
accepted = [tcvc addURL:[NSURL URLWithString:@"http://www.twitter.com/"]]; // This won't work either. Only three URLs allowed, just like Apple's implementation.
[tcvc addImage:[UIImage imageNamed:@"YawkeyBusinessDog.jpg"]];
[tcvc addImage:[UIImage imageNamed:@"YawkeyCleanTeeth.jpg"]]; // This one won't actually work. Only one image per tweet allowed currently by Twitter.
[tcvc addURL:[NSURL URLWithString:@"http://www.DoubleEncore.com/"]];
[tcvc addURL:[NSURL URLWithString:@"http://www.apple.com/ios/features.html#twitter"]];
[tcvc addURL:[NSURL URLWithString:@"http://www.twitter.com/"]]; // This won't work either. Only three URLs allowed, just like Apple's implementation.
NSString *tweetText = [self.tweets objectAtIndex:arc4random() % [self.tweets count]];
accepted = [tcvc setInitialText:tweetText];
[tcvc setInitialText:tweetText];
}


#pragma mark - Actions

- (IBAction)tweetUs:(id)sender
{
if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
[self tweetUs];
}
else {
Expand All @@ -216,7 +214,7 @@ - (IBAction)tweetUs:(id)sender
[self tweetUs];
}
else {
if ([UIApplication isIOS5]) {
if ([UIDevice de_isIOS5]) {
[self tweetUs];
[DETweetComposeViewController displayNoTwitterAccountsAlert];
}
Expand Down
4 changes: 2 additions & 2 deletions README.markdown
Expand Up @@ -28,7 +28,7 @@ As you can see they look very similar.
3. Link your project against the follwoing frameworks:
1. Accounts.framework
2. Twitter.framework.
4. Set your Twitter OAuth Consumer Key and Consumer Secret in OAuthConsumerCredentials.h in your project, you will find this file in unoffical-twitter-sdk/OAuth. Don't have an OAuth consumer key and secret? Go to developer.twitter.com to create an app.
4. Set your Twitter OAuth Consumer Key and Consumer Secret in OAuthConsumerCredentials.h in your project, you will find this file in unoffical-twitter-sdk/OAuth. Don't have an OAuth consumer key and secret? Go to developer.twitter.com to create an app. Make sure your app's Access is set to 'Read and Write' and a Callback URL is defined. Both of these configurations can be found under the Settings of your Twitter app.
5. You will notice there is an #error in OAuthConsumerCredentials.h to help ensure you remember to add your Twitter OAuth credentials, remember to delete this #error after you have added your OAuth credentials.
6. Use it almost just like you would a TWTweetComposeViewController

Expand Down Expand Up @@ -70,4 +70,4 @@ We have some TODO items in [github Issues](https://github.com/doubleencore/DETwe
## Credits

1. unofficial-twitter-sdk [lloydsparkes](https://github.com/lloydsparkes)
2. InnerShadowDrawing [mruegenberg](https://github.com/mruegenberg/objc-utils/tree/master/UIKitAdditions)
2. InnerShadowDrawing [mruegenberg](https://github.com/mruegenberg/objc-utils/tree/master/UIKitAdditions)

0 comments on commit 09dc722

Please sign in to comment.