Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Native Twitter support in iOS 5+

Via Can Durakci (@iphoneuygulama) aka jazzbass on the NK Forums -
thanks Can!
  • Loading branch information...
commit 87d5206127c95c5d6592efb71be2df2968f063e6 1 parent 7864a93
@pixelspring pixelspring authored
View
11 Classes/MyPickerController.m
@@ -30,20 +30,25 @@ - (void)showMyPicker
_picker.dataSource = self;
_picker.delegate = self;
_picker.showsSelectionIndicator = YES;
- [_picker selectRow:1 inComponent:1 animated:YES];
- [_picker selectRow:1 inComponent:0 animated:YES];
+ [_picker selectRow:1 inComponent:1 animated:YES]; // Set Selected Row
+ [_picker selectRow:1 inComponent:0 animated:YES]; // Set Selected Row
[_webView addSubview:_picker ];
//[(UIView*)[[_picker subviews] objectAtIndex:2] setAlpha:0.1f];
+ // ==================================================================================
+ // Use this to place an image over the picker to give impression of a custom skin
+ // ==================================================================================
+ /*
CGRect myImageRect = CGRectMake(0.0f, 210.0f, 320.0f, 162.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"pickover.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[_webView addSubview:myImage];
[myImage release];
-
+ */
+ // ==================================================================================
[_picker release];
}
View
29 Classes/TObject.h
@@ -0,0 +1,29 @@
+//
+// TObject.h
+// TDeneme
+//
+// Created by Can Durakci on 11/22/11.
+// Jazzbass
+// Copyright (c) 2011 Unimedisys. All rights reserved. visit www.unimedisys.com
+//
+
+#import <Foundation/Foundation.h>
+
+@interface TObject : NSObject
+{
+ NSDictionary* _parameters;
+ UIWebView* _webView;
+ NSString* _pageTitle;
+ NSString* _lastReturnResult;
+ NSMutableArray* _components;
+ UIView *overlay;
+ UIViewController* _nimbleViewController;
+}
+@property (retain) NSDictionary* _parameters;
+@property (retain) UIWebView* _webView;
+@property (retain) NSString* _pageTitle;
+@property (retain) NSString* _lastReturnResult;
+@property (retain) UIViewController* _nimbleViewController;
+
+
+@end
View
81 Classes/TObject.m
@@ -0,0 +1,81 @@
+//
+// TObject.m
+// TDeneme
+//
+// Created by Can Durakci on 11/22/11.
+// Jazzbass
+// Copyright (c) 2011 Unimedisys. All rights reserved. visit www.unimedisys.com
+//
+
+#import "TObject.h"
+#import "Nimble.h"
+#import "NKBridge.h"
+#import <Twitter/Twitter.h>
+
+@implementation TObject
+@synthesize _nimbleViewController;
+@synthesize _parameters, _webView, _pageTitle, _lastReturnResult;
+
+-(void)tweetIt // For some reason, if the function is named "tweet", any instances of the word "tweet" are removed???
+{
+ NSLog(@"Tweeting!");
+
+ NSString* message = [_parameters objectForKey:@"message"];
+
+ if ([TWTweetComposeViewController canSendTweet])
+ {
+ TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
+ [tweetSheet setInitialText:message];
+ [tweetSheet addImage:[UIImage imageNamed:@"Icon@2x.png"]]; // Optionally add an image to the tweet if you so desire - some nice app branding maybe ;)
+
+ UIViewController* controller = [[NSClassFromString(@"NKBridge") sharedInstance] navigationControllerForPage:@"main.html"];
+ if(!controller)
+ controller = [[NSClassFromString(@"NKBridgeInternal") sharedInstance] _nimbleViewController];
+ [controller presentModalViewController:tweetSheet animated:YES];
+
+ }
+ else
+ {
+ UIAlertView *alertView = [[UIAlertView alloc]
+ initWithTitle:@"Sorry"
+ message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
+ delegate:self
+ cancelButtonTitle:@"OK"
+ otherButtonTitles:nil];
+ [alertView show];
+ }
+
+
+}
+
+
+#pragma mark -
+#pragma mark automatic setter methods
+
+- (void)setNKParameters:(NSDictionary*)parameters
+{
+ self._lastReturnResult = nil;
+ self._parameters = parameters;
+}
+
+- (void)setNKCurrentPage:(NSString*)pageTitle
+{
+ self._pageTitle = pageTitle;
+}
+
+- (void)setNKWebView:(UIWebView*)webView
+{
+ self._webView = webView;
+}
+
+- (void) dealloc
+{
+ self._pageTitle = nil;
+ self._parameters = nil;
+ self._webView = nil;
+ self._lastReturnResult = nil;
+ [super dealloc];
+}
+
+@end
+
View
7 Classes/locale.m
@@ -37,7 +37,12 @@ - (void)getLocale
}
-
+#pragma mark getLang
+- (void)getLang {
+ self.result = [[NSLocale preferredLanguages] objectAtIndex:0];
+
+
+}
#pragma mark methodResult
View
12 ObjC-Mix.xcodeproj/project.pbxproj
@@ -45,6 +45,8 @@
1EA722A413360F3900CDC608 /* pickerview.html in Resources */ = {isa = PBXBuildFile; fileRef = 1EA722A313360F3900CDC608 /* pickerview.html */; };
1EA84A37137E96230033C6EF /* README.txt in Resources */ = {isa = PBXBuildFile; fileRef = 1EA84A36137E96230033C6EF /* README.txt */; };
1ECBCC3E138FB1CF0062D8F4 /* segmentedcontrol.html in Resources */ = {isa = PBXBuildFile; fileRef = 1ECBCC3D138FB1CF0062D8F4 /* segmentedcontrol.html */; };
+ 1ECD2942147BF69200FABDB0 /* TObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ECD2941147BF69200FABDB0 /* TObject.m */; };
+ 1ECD294A147BFAE500FABDB0 /* Twitter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ECD2949147BFAE500FABDB0 /* Twitter.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
1ECF7CAC13CC867800EB08E9 /* getFreeSpace.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ECF7CAB13CC867800EB08E9 /* getFreeSpace.m */; };
1ED63A8214658E350035B7F3 /* myscheme.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ED63A8114658E350035B7F3 /* myscheme.m */; };
1ED63A8414658E820035B7F3 /* urlschemas.html in Resources */ = {isa = PBXBuildFile; fileRef = 1ED63A8314658E820035B7F3 /* urlschemas.html */; };
@@ -124,6 +126,9 @@
1EA722A313360F3900CDC608 /* pickerview.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = pickerview.html; sourceTree = "<group>"; };
1EA84A36137E96230033C6EF /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
1ECBCC3D138FB1CF0062D8F4 /* segmentedcontrol.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = segmentedcontrol.html; sourceTree = "<group>"; };
+ 1ECD2941147BF69200FABDB0 /* TObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TObject.m; sourceTree = "<group>"; };
+ 1ECD2949147BFAE500FABDB0 /* Twitter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Twitter.framework; path = System/Library/Frameworks/Twitter.framework; sourceTree = SDKROOT; };
+ 1ECD294B147C0BDF00FABDB0 /* TObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TObject.h; sourceTree = "<group>"; };
1ECF7CAA13CC867800EB08E9 /* getFreeSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getFreeSpace.h; sourceTree = "<group>"; };
1ECF7CAB13CC867800EB08E9 /* getFreeSpace.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = getFreeSpace.m; sourceTree = "<group>"; };
1ED63A8014658E350035B7F3 /* myscheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = myscheme.h; sourceTree = "<group>"; };
@@ -160,8 +165,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 1ECD294A147BFAE500FABDB0 /* Twitter.framework in Frameworks */,
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
- 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */,
BEAC17B40F98BE5300A76568 /* AddressBook.framework in Frameworks */,
BEAC17CA0F98BE7700A76568 /* CFNetwork.framework in Frameworks */,
@@ -174,6 +179,7 @@
BEAD72F20FF0358D00C589B0 /* MediaPlayer.framework in Frameworks */,
BE4B710610AC96A6004234DA /* MapKit.framework in Frameworks */,
BE4B711510AC96AD004234DA /* StoreKit.framework in Frameworks */,
+ 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -223,6 +229,8 @@
1E9F26BC138ACED700087125 /* MyUISearchBar.m */,
1E9F26BE138BA9F000087125 /* segment.h */,
1E9F26BF138BA9F100087125 /* segment.m */,
+ 1ECD294B147C0BDF00FABDB0 /* TObject.h */,
+ 1ECD2941147BF69200FABDB0 /* TObject.m */,
1EC715AB13925CF00009F1E9 /* Experimental / WIP */,
);
path = Classes;
@@ -289,6 +297,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 1ECD2949147BFAE500FABDB0 /* Twitter.framework */,
BE4B711410AC96AD004234DA /* StoreKit.framework */,
BE4B710510AC96A6004234DA /* MapKit.framework */,
BE44BC4D0FCADCA500A143AD /* libNimbleKit.a */,
@@ -434,6 +443,7 @@
1E0A643D13D42F1500E117D8 /* checkJailbreak.m in Sources */,
1E6490AE140FBC0C0097C5F6 /* undetectTel.m in Sources */,
1ED63A8214658E350035B7F3 /* myscheme.m in Sources */,
+ 1ECD2942147BF69200FABDB0 /* TObject.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
34 main.html
@@ -41,6 +41,7 @@
NKRegisterClass("getFreeSpace");
NKRegisterClass("checkJailbreak");
+NKRegisterClass("TObject");
// Battery Status
@@ -65,6 +66,13 @@
NKAlert("Your Device Country Code Is:", locale);
}
+// Get Device Country Code
+function getLang()
+{
+ var locale = CallNKitAction('getLang?className=locale&sync=yes');
+ NKAlert("Your ISO 639-1 Language Code Is:", locale);
+}
+
// Get Left Button Tap
function leftButtonClicked()
@@ -120,6 +128,30 @@
}
// ************************************************************************
+
+
+
+
+// ************************************************************************
+// Send a tweet in iOS 5
+//
+// Remember to add the Twitter & UIKit frameworks to your project and to
+// add a device version check (ie, only for iOS 5+)
+//
+// Also recommended, "weak link" the Twitter framework: select your target,
+// select the "Summary" tab, select the framework in "Linked Frameworks and
+// Libraries" and change from "Required" to "Optional"
+// ************************************************************************
+
+var tweetMessage = "This is a tweetage sent via a NimbleKit app with Obj-C/js mix";
+
+function sendTweet()
+{
+ CallNKitAction("tweetIt?className=TObject&message="+tweetMessage);
+}
+
+// ************************************************************************
+
</script>
@@ -134,6 +166,7 @@
<li><a onClick="CallNKitAction('removeLeftButton?className=leftButton')">Hide Left Button</a></li>
<li><a onClick="getLocale()">Get Locale</a></li>
<li><a onClick="getLocation()">Get Location</a></li>
+<li><a onClick="getLang()">Get Language Code</a></li>
<li><a onClick="CallNKitAction('dummy?className=deShadow')">Remove UIWebView Shadow</a></li>
<!-- ********************************************************
@@ -150,6 +183,7 @@
<li><a onClick="CallNKitAction('checkForJailbreak?className=checkJailbreak')">Check For Jailbreak</a></li>
<li><a onClick="navController.gotoPage('undetecttel.html')">Tel. No. Detection</a></li>
<li><a onClick="navController.gotoPage('urlschemas.html')">URL Schemas</a></li>
+<li><a onClick="sendTweet()">Send a Tweet</a></li>
<!-- ********************************************************
<--- NOT YET WORKING and/or CRASHY
Please sign in to comment.
Something went wrong with that request. Please try again.