On lots of searching about Rabbit MQ I found objective C wrapper for librabbitmq-c whose link is directed to librabbitmq-objc.
For librabbitmq-c link found https://github.com/alanxz/rabbitmq-c.
I tried to integrate both in my application by lots of error are produced like
i) <Cocoa/Cocoa.h> file not found
ii) <amqp.h> file not found
iii)Too few arguements passing to amqp_basic_consume() method in AMQPConsumer.m
iv) Use of undeclared identifier AMQ_PLATFORM in amqp_socket.c file.
v) Use of undeclared identifier AMQP_EXCHANGE_TYPE_DIRECT in AMQPExchange.m
vi) ""---------""----- ""------- AMQP_EXCHANGE_TYPE_FANOUT in ""---""-------
vii)--""-----------""----------- AMQP_EXCHANGE_TYPE_TOPIC in ""----""-------
I also tried latest version of librabbitmq-c from this link https://github.com/alanxz/rabbitmq-c/releases/download/v0.5.2/rabbitmq-c-0.5.2.tar.gz
First and second issue solved by replacing <Cocoa/Cocoa.h> with <Foundation/Foundation.h>
and <amqp.h> with "amqp.h"
But I am not able to solve rest of them
My client library implementation is given below:-
NSString *workQueueName = #"MyQueue";
AMQPExchange *exchange;
AMQPConnection *connection = [[AMQPConnection alloc] init];
[connection connectToHost:#"localhost" onPort:5672];
[connection loginAsUser:#"guest" withPasswort:#"guest" onVHost:#"/"];
AMQPChannel *receiverChannel = [connection openChannel];
AMQPQueue *queue = [[AMQPQueue alloc] initWithName:workQueueName
onChannel:receiverChannel
isPassive:NO
isExclusive:NO
isDurable:NO
getsAutoDeleted:YES];
exchange = [[AMQPExchange alloc] initFanoutExchangeWithName:#"EXCHANGE_NAME" onChannel:receiverChannel isPassive:NO isDurable:NO getsAutoDeleted:NO];
[queue bindToExchange:exchange withKey:workQueueName];
AMQPConsumer *consumer = [[AMQPConsumer alloc] initForQueue:queue onChannel:receiverChannel useAcknowledgements:NO isExclusive:NO receiveLocalMessages:YES];
AMQPConsumerThread *wqThread = [[AMQPConsumerThread alloc] initWithConsumer:consumer];
wqThread.delegate = self;
[wqThread start];
Any help regarding Rabbit MQ will be appreciated, thanks
After long period of time I have solved it.
Please refer this link for library
https://dl.dropboxusercontent.com/u/75870052/AMQPLib.zip
and refer following link for detail...
https://stackoverflow.com/a/26601155/1305001
Related
Firstly, as I see many others seem to announce when they ask these types of questions, I'm a beginner to Objective C. I've come from a strong PHP background, so I do understand most programming concepts, and have been learning Obj C on and off for the past 12 months.
One of my first projects to get my feet wet with iOS Objective C was to integrate with the Magento SOAP API. Probably not the easiest thing to begin with, but nonetheless it's a good challenge.
I'm currently trying to integrate XMLReader (https://github.com/amarcadet/XMLReader). But XCode keeps throwing me an error:
ARC Semantic Issue: No known class method for selector 'dictionaryForNSXMLParser:'
Which refers to the following code:
NSDictionary *dict = [XMLReader dictionaryForNSXMLParser:parser];
I found some advice from another question:
How can you use AFNetworking or STHTTPRequest to make a request of a SOAP web service?
I've reverted my code to mirror exactly the examples provided in the question, so I've been wracking my brain to work this error out, but to no avail.
Any help is much appreciated, and I apologise if this is something stupid which I have overlooked. I've tried scouring google for similar issues, but they all seem to be leading to class methods being called on an instance, etc.
I was trying that code myself just a minute ago.
You have to add in XMLReader.h:
+(NSDictionary*)dictionaryForNSXMLParser:(NSXMLParser*)parser error:(NSError **)error;
Then in the XMLReader.m these two:
+ (NSDictionary *)dictionaryForNSXMLParser:(NSXMLParser *)xmlParser error:(NSError **)error
{
XMLReader *reader = [[XMLReader alloc] initWithError:error];
NSDictionary *rootDictionary = [reader objectWithNSXMLParser:xmlParser options:0];
return rootDictionary;
}
- (NSDictionary *)objectWithNSXMLParser:(NSXMLParser *)xmlParser options:(XMLReaderOptions)options
{
// Clear out any old data
self.dictionaryStack = [[NSMutableArray alloc] init];
self.textInProgress = [[NSMutableString alloc] init];
// Initialize the stack with a fresh dictionary
[self.dictionaryStack addObject:[NSMutableDictionary dictionary]];
[xmlParser setShouldProcessNamespaces:(options & XMLReaderOptionsProcessNamespaces)];
[xmlParser setShouldReportNamespacePrefixes:(options & XMLReaderOptionsReportNamespacePrefixes)];
[xmlParser setShouldResolveExternalEntities:(options & XMLReaderOptionsResolveExternalEntities)];
xmlParser.delegate = self;
BOOL success = [xmlParser parse];
// Return the stack's root dictionary on success
if (success)
{
NSDictionary *resultDict = [self.dictionaryStack objectAtIndex:0];
return resultDict;
}
return nil;
}
After that remember to import XMLReader.h and use the method. Notice that it has the error handling in it so if you copy pasted the code it's not same.
[XMLReader dictionaryForNSXMLParser:parser error:nil];
If it still doesn't work try cleaning the project with CMD+SHIFT+K and building it again.
I am trying to create a signature for AWS signature as described in this doc.
The Doc has Java code i need equivalent Objective-c Code
http://docs.aws.amazon.com/general/latest/gr/signature-version-2.html
I have made a class AWSRequest
// AWSRequest.h
#import <Foundation/Foundation.h>
#import "../AmazonServiceRequest.h"
#interface AWSRequest : AmazonServiceRequest
- (void)makeSignature;
#end
Implement
// AWSRequest.m
#import "AWSRequest.h"
#import <AWSiOSSDK/AWSRuntime.h>
#import "AmazonAuthUtils.h"
#implementation AWSRequest
-(void)makeSignature
{
NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970];
float finalTime = timeInterval;
NSString *sendTimeStamp = F(#"%0.f%#", finalTime , #"000");
[self setParameterValue:credentials.accessKey forKey:#"AWSAccessKeyId"];
[self setParameterValue:#"2" forKey:#"SignatureVersion"];
[self setParameterValue:sendTimeStamp forKey:#"Timestamp"];
[self setParameterValue:#"HmacSHA256" forKey:#"SignatureMethod"];
NSData *dataToSign = [[AmazonAuthUtils getV2StringToSign:[NSURL URLWithString:self.endpoint] request:self] dataUsingEncoding:NSUTF8StringEncoding];
NSString *signature = [AmazonAuthUtils HMACSign:dataToSign withKey:credentials.secretKey usingAlgorithm:kCCHmacAlgSHA256];
[self setParameterValue:signature forKey:#"Signature"];
}
Then the following methods calls the service
NSString *accessKey = #"Q_____O";
NSString *secretKey = #"2____2";
AmazonCredentials *credentials = [[AmazonCredentials alloc] initWithAccessKey:accessKey withSecretKey:secretKey];
AmazonServiceRequest *serviceRequest = [[AmazonServiceRequest alloc] init];
serviceRequest.credentials = credentials;
AWSRequest *request = [[AWSRequest alloc] init];
request.credentials = credentials;
request.delegate = self;
[request makeSignature];
Is there something wrong in the code ? Like using the TimeStamp etc as i am always getting Unauthorized error from web service.
Following links might be helpful
http://www.cocoanetics.com/2013/07/talking-to-amazon-web-services/
http://mobile.awsblog.com/post/Tx296UMHAW17ZOV/Using-Different-AWS-Regions-with-the-AWS-Mobile-SDKs
http://mobile.awsblog.com/post/Tx31X75XISXHRH8/Managing-Credentials-in-Mobile-Applications
Which service are you using? Most services now require signature version 4.
You link to our blog, but are you aware of the AWS SDK for iOS? Even if you don't want to use the SDK directly, the source code is available on GitHub so you can compare your implementation versus our official one.
I have been pouring over the internet for days now trying to figure out how to implement this.
I need to request the access token and secret from twitter in order to pass this to a server that will process the users tweets for my application.
I have been following this link https://dev.twitter.com/docs/ios/using-reverse-auth
The problem is step 1. They dont give you an example of step 1.
Here is my code:
NSURL *url = [NSURL URLWithString:TW_OAUTH_URL_REQUEST_TOKEN];
NSDictionary *parameters = #{TW_X_AUTH_MODE_KEY:TW_X_AUTH_MODE_REVERSE_AUTH};
SLRequest *getTwitterAuth = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:parameters];
// Assume that we stored the result of Step 1 into a var 'resultOfStep1'
NSString *S = resultOfStep1;
NSDictionary *step2Params = [[NSMutableDictionary alloc] init];
[step2Params setValue:#"kfLxMJsk7fqIuy8URhleFg" forKey:#"x_reverse_auth_target"];
[step2Params setValue:S forKey:#"x_reverse_auth_parameters"];
NSURL *url2 = [NSURL URLWithString:#"https://api.twitter.com/oauth/access_token"];
SLRequest *stepTwoRequest =
[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url2 parameters:step2Params];
// You *MUST* keep the ACAccountStore alive for as long as you need an ACAccount instance
// See WWDC 2011 Session 124 for more info.
self.accountStore = [[ACAccountStore alloc] init];
// We only want to receive Twitter accounts
ACAccountType *twitterType =
[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Obtain the user's permission to access the store
[self.accountStore requestAccessToAccountsWithType:twitterType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// handle this scenario gracefully
} else {
// obtain all the local account instances
NSArray *accounts =
[self.accountStore accountsWithAccountType:twitterType];
// for simplicity, we will choose the first account returned - in your app,
// you should ensure that the user chooses the correct Twitter account
// to use with your application. DO NOT FORGET THIS STEP.
[stepTwoRequest setAccount:[accounts objectAtIndex:0]];
// execute the request
[stepTwoRequest performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *responseStr =
[[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
// see below for an example response
NSLog(#"The user's info for your server:\n%#", responseStr);
}];
}
}];
I have been trying to figure out how I process the SLRequest in oder to pass it to step 2 from the twitter docs.
I have also used this here: https://github.com/seancook/TWReverseAuthExample
This code is great but very complex. Any help would be greatly appreciated! Thanks!
The reason step one doesn't have any code is that they assume you will do this on your server or before hand or something like that. Basically you need to generate a key that your app will use to convert iOS tokens to normal tokens.
There is a script that will make the request for you here: http://www.ananseproductions.com/twitter-reverse-auth-headaches/ Its written in ruby so you could use something similar if you have a ruby server.
Personally I would have my app request this token from my server, then make the request to twitter, then post the new token back to my server.
Here is a class to help accomplish just this with a single method call that returns a dictionary with the token and token secret.
https://github.com/kbegeman/Twitter-Reverse-Auth
Hope this helps others out!
As of this code https://github.com/seancook/TWReverseAuthExample , it's fairly simple to implement in your own application. I prefer to create reusable classes, so I don't have to implement the same code multiple times. Normally you would create some singleton and work with it on the following tutorial. However the point of this instruction is not to teach you how to create singletons, so for the simplicity sake, we will use AppDelegate.h/m which is easily accessible from all over the application.
All you have to do is the following:
Open yours and Sean Cook's project (the one which URL is above)
Drag and copy Source->Vendor->ABOauthCore group into your project
Select TWAPIManager.h/m, TWSignedRequest.h/m and copy them into your project
Add the below code into your AppDelegate.h file
#property (nonatomic, strong) ACAccountStore* store;
#property (nonatomic, strong) TWAPIManager *apiManager;
#property (nonatomic, strong) NSArray *accounts;
-(void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret;
-(void)performReverseAuth:(id)sender inView:(UIView*)viewToDisplaySheet;
-(void)_refreshTwitterAccounts;
Now paste the following methods into your AppDelegate.m file
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
-(void)_refreshTwitterAccounts;
-(void)_obtainAccessToAccountsWithBlock:(void (^)(BOOL))block;
-(void)performReverseAuth:(id)sender inView:(UIView*)viewToDisplaySheet;
In some initialization method of your file, or as of this example in: `application: didFinishLaunchingWithOptions' paste the following code:
_store = [[ACAccountStore alloc] init];
_apiManager = [[TWAPIManager alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(_refreshTwitterAccounts) name:ACAccountStoreDidChangeNotification object:nil];
Remember to remove observer using the following code. Paste it in AppDelegate.m:
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Open your app-Info.plist file and add 2 string keys. Take their values from: https://apps.twitter.com/
TWITTER_CONSUMER_KEY
TWITTER_CONSUMER_SECRET
In the View Controller that you want to use to implement twitter features, in the viewDidLoad method, add the following code:
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate _refreshTwitterAccounts];
OK, finally you are ready to start the whole machine. In the View Controller that you want to use to implement twitter features, create UIButton called _reverseAuthBtn and create an IBAction to it. Then in your IBAction paste the following code:
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate performReverseAuth:sender inView:self.view];
Whew, I guess that's it! If I haven't forgotten about anything, you have got Twitter Reverse Oauth implementation, and if you want to use it in multiple view controllers, all you have to do is do steps 1-8, and then paste the code from the steps 9 and 10 into your view controller.
Best regards!
Use this lib, it works perfectly!
https://github.com/nst/STTwitter
Info how to implement: https://github.com/nst/STTwitter#reverse-authentication
:)
Hiii..
I am creating one application in which i am using web service named "http://192.168.0.51/iPadDataCollection/Service.svc?wsdl" . I have parsed class from this web service and i have written the code to access one method named TestConnection but i am getting error 400 (Bad Request).
Can anyone help me to solve this issue??
Thanx in advance.
BasicHttpBinding_IServiceBinding *binding=[[Service BasicHttpBinding_IServiceBinding]initWithAddress:#"http://192.168.0.51/iPadDataCollection/Service.svc?wsdl"];
binding.logXMLInOut = YES;
Service_TestConnection *request = [[Service_TestConnection alloc] init];
request.Unique_Id =txtID.text;
[binding TestConnectionAsyncUsingParameters:request delegate:self];
[spinner startAnimating];
[request release];
In Facebook iOS SDK, I can ask for queries like this:
[_facebook requestWithGraphPath:#"me/feed" andDelegate:self];
But often Facebook will give a limited JSON response with a URL to be used to request to move to earlier dates, for example. So in the JSON response, I'll have:
data = ( /*things here... status updates, photos, etc...*/
);
paging = {
next = "https://graph.facebook.com/me/feed?sdk=ios&sdk_version=2&access_token= <something>&until=2010-12-04";
previous = "https://graph.facebook.com/me/feed?sdk=ios&sdk_version=2&access_token=<something>&since=<something>";
};
What I'm wondering is... How do I go to the previous URL? Does the SDK provide an interface to do this?
EDIT: If possible, I actually want answer with Graph API, as Facebook is currently deprecating the REST API.
BONUS: If anyone can explain the time format that's returned by Facebook. I have 2010-09-13T00%3A25%3A16%2B0000 as an example.
all what you need that add a method to the Facebook subclass or itself
- (void)requestWithURLString:(NSString *)fullURL
andHttpMethod:(NSString *)httpMethod
andDelegate:(id <FBRequestDelegate>)delegate {
[self openUrl:fullURL params:nil httpMethod:httpMethod delegate:delegate];
}
ps the second param "httpMethod" may be always #"GET" you can omit it
With Facebook's iOS SDK version 3 out, the original answer no longer applies to the current version.
I had to do some digging, because the new version doesn't make this any easier. I found an example of how to get this done in the FBGraphObjectPagingLoader class that the new SDK provides to help do this for tables. It's incredibly ugly, but I assume that it's the "recommended" method since it's what they use.
Here's my slight modification of their code (found originally in FBGraphObjectPagingLoader's followNextLink method)
FBRequest *request = [[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:nil] autorelease];
FBRequestConnection *connection = [[[FBRequestConnection alloc] init] autorelease];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// Do some stuff
}];
// Override the URL using the one passed back in 'next'.
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
connection.urlRequest = urlRequest;
[connection start];
You could of course modify their library and encapsulate this in the class itself if you wanted to.
You can do something like this:
[appDelegate.fb requestWithGraphPath:#"me/home"
andParams:[NSMutableDictionary dictionaryWithObject:#"2011-01-27T04%3A48%3A50%2B0000" forKey:#"since"]
andDelegate:self];
Notice that, in the paging portion of your feed, the next and previous URLs differ just by one query parameter (until and since). You can use the values you grab from this to get the next and previous page of results.
Hope this helps!
Yes you can get the result by calling the function in api
I used below code to get the statuses of users in your case you can use stream.get method you can found it here http://developers.facebook.com/docs/reference/rest/stream.get/
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
[params setValue:[NSString stringWithFormat:#"%#", appDelegate.user_id] forKey:#"uid"];
[params setValue:#"150" forKey:#"limit"];
[params setValue:#"results" forKey:#"callback"];
[_facebook requestWithMethodName: #"status.get"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
You can use this code for you purpose.
At least as far as the date format goes, its a variant of RFC 3339 format. As far as I know, iOS doesn't have a pre-defined formatter of that type.
I create a date formatter and keep it around (they're are strangely slow to create) so I can easily convert them when working with FB data.
NSDateFormatter * sRFC3339DateFormatter = nil;
NSLocale * enUSPOSIXLocale;
sRFC3339DateFormatter = [[NSDateFormatter alloc] init];
enUSPOSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier:#"en_US_POSIX"] autorelease];
[sRFC3339DateFormatter setLocale:enUSPOSIXLocale];
[sRFC3339DateFormatter setDateFormat:#"yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"];
[sRFC3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
Once you have such a formatter, you can easily convert back and forth.
NSDate* myDate = nil;
myDate = [sRFC3339DateFormatter dateFromString:#"2011-01-27T04%3A48%3A50%2B0000"];
Breaking the URL up into a dictionary of strings is pretty straightforward with NSURL methods.