mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
@@ -17,28 +17,25 @@ TwitterDemo = {
|
||||
},
|
||||
|
||||
setup:function(){
|
||||
var tests = ["isAvailable", "isSetup", "tweet", "compose", "timeline", "mentions"];
|
||||
var tests = ["isAvailable", "isSetup", "tweet", "timeline", "mentions"];
|
||||
for(var i=0, l=tests.length; i<l; i++){
|
||||
this.$(tests[i]).onclick = this[tests[i]];
|
||||
}
|
||||
},
|
||||
|
||||
isAvailable:function(){
|
||||
TwitterDemo.log("wait..");
|
||||
window.plugins.twitter.isTwitterAvailable(function(r){
|
||||
TwitterDemo.log("twitter available? " + r);
|
||||
});
|
||||
},
|
||||
|
||||
isSetup:function(){
|
||||
TwitterDemo.log("wait..");
|
||||
window.plugins.twitter.isTwitterSetup(function(r){
|
||||
TwitterDemo.log("twitter configured? " + r);
|
||||
});
|
||||
},
|
||||
|
||||
tweet:function(){
|
||||
TwitterDemo.log("wait..");
|
||||
window.plugins.twitter.sendTweet(
|
||||
function(s){ TwitterDemo.log("tweet success"); },
|
||||
function(e){ TwitterDemo.log("tweet failure: " + e); },
|
||||
@@ -48,19 +45,16 @@ TwitterDemo = {
|
||||
},
|
||||
|
||||
compose: function() {
|
||||
TwitterDemo.log("wait..");
|
||||
window.plugins.twitter.composeTweet();
|
||||
},
|
||||
|
||||
timeline:function(){
|
||||
TwitterDemo.log("wait..");
|
||||
window.plugins.twitter.getPublicTimeline(
|
||||
function(s){ TwitterDemo.log("timeline success: " + JSON.stringify(s)); },
|
||||
function(e){ TwitterDemo.log("timeline failure: " + e); });
|
||||
},
|
||||
|
||||
mentions:function(){
|
||||
TwitterDemo.log("wait..");
|
||||
window.plugins.twitter.getMentions(
|
||||
function(s){ TwitterDemo.log("mentions success: " + JSON.stringify(s)); },
|
||||
function(e){ TwitterDemo.log("mentions failure: " + e); });
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<meta charset="utf-8">
|
||||
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="TwitterPlugin.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="demo.js"></script>
|
||||
</head>
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#import "TwitterPlugin.h"
|
||||
#ifdef PHONEGAP_FRAMEWORK
|
||||
#import <PhoneGap/JSONKit.h>
|
||||
#import <PhoneGap/JSON.h>
|
||||
#else
|
||||
#import "JSONKit.h"
|
||||
#import "JSON.h"
|
||||
#endif
|
||||
|
||||
#define TWITTER_URL @"http://api.twitter.com/1/"
|
||||
@@ -94,12 +94,14 @@
|
||||
}
|
||||
|
||||
- (void) composeTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
|
||||
TWTweetComposeViewController *tweetComposeViewController = [[TWTweetComposeViewController alloc] init];
|
||||
[tweetComposeViewController setCompletionHandler: ^(TWTweetComposeViewControllerResult result) {
|
||||
[[super appViewController] dismissModalViewControllerAnimated:YES];
|
||||
}];
|
||||
TWTweetComposeViewController *tweetComposeViewController =
|
||||
[[TWTweetComposeViewController alloc] init];
|
||||
[tweetComposeViewController setCompletionHandler:
|
||||
^(TWTweetComposeViewControllerResult result) {
|
||||
[[ super appViewController ] dismissModalViewControllerAnimated:YES];
|
||||
}];
|
||||
|
||||
[[super appViewController] presentModalViewController:tweetComposeViewController animated:YES];
|
||||
[[ super appViewController ] presentModalViewController:tweetComposeViewController animated:YES];
|
||||
}
|
||||
|
||||
- (void) getPublicTimeline:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
|
||||
@@ -113,7 +115,7 @@
|
||||
if([urlResponse statusCode] == 200) {
|
||||
|
||||
NSString *dataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
|
||||
NSDictionary *dict = [dataString objectFromJSONString];
|
||||
NSDictionary *dict = [dataString JSONValue];
|
||||
jsResponse = [[PluginResult resultWithStatus:PGCommandStatus_OK messageAsDictionary:dict] toSuccessCallbackString:callbackId];
|
||||
[dataString release];
|
||||
}
|
||||
@@ -147,7 +149,7 @@
|
||||
NSString *jsResponse;
|
||||
if([urlResponse statusCode] == 200) {
|
||||
NSString *dataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
|
||||
NSDictionary *dict = [dataString objectFromJSONString];
|
||||
NSDictionary *dict = [dataString JSONValue];
|
||||
jsResponse = [[PluginResult resultWithStatus:PGCommandStatus_OK messageAsDictionary:dict] toSuccessCallbackString:callbackId];
|
||||
[dataString release];
|
||||
}
|
||||
|
||||
33
iPhone/Twitter/www/TwitterPlugin.js
Normal file
33
iPhone/Twitter/www/TwitterPlugin.js
Normal file
@@ -0,0 +1,33 @@
|
||||
var Twitter = function(){};
|
||||
|
||||
Twitter.prototype.isTwitterAvailable = function(response){
|
||||
PhoneGap.exec(response, null, "com.phonegap.twitter", "isTwitterAvailable", []);
|
||||
};
|
||||
|
||||
Twitter.prototype.isTwitterSetup = function(response){
|
||||
PhoneGap.exec(response, null, "com.phonegap.twitter", "isTwitterSetup", []);
|
||||
};
|
||||
|
||||
Twitter.prototype.sendTweet = function(success, failure, tweetText, urlAttach, imageAttach){
|
||||
if(typeof urlAttach === "undefined") urlAttach = "";
|
||||
if(typeof imageAttach === "undefined") imageAttach = "";
|
||||
|
||||
PhoneGap.exec(success, failure, "com.phonegap.twitter", "sendTweet", [tweetText, urlAttach, imageAttach]);
|
||||
};
|
||||
|
||||
Twitter.prototype.composeTweet = function() {
|
||||
PhoneGap.exec(null, null, "com.phonegap.twitter", "composeTweet", []);
|
||||
};
|
||||
|
||||
Twitter.prototype.getPublicTimeline = function(success, failure){
|
||||
PhoneGap.exec(success, failure, "com.phonegap.twitter", "getPublicTimeline", []);
|
||||
};
|
||||
|
||||
Twitter.prototype.getMentions = function(success, failure){
|
||||
PhoneGap.exec(success, failure, "com.phonegap.twitter", "getMentions", []);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
if(!window.plugins) window.plugins = {};
|
||||
window.plugins.twitter = new Twitter();
|
||||
});
|
||||
Reference in New Issue
Block a user