Instant Message Framework example - objective-c

Can someone show an example on how to log in to AIM, then send and receive messages using the IMframework?
Thanks!

I am the author of an Objective-C library for AOL instant messenger. It provides a simple Object Oriented approach to instant messaging. People have used it in the past to develop iOS IM applications, and even added on to it to support things like Off-The-Record. You can check it out on github, download the source, and add the source to your application by manually copying them. Once you have the code in your project, you can sign in like this:
AIMLogin * login = [[AIMLogin alloc] initWithUsername:username password:password];
[login setDelegate:self];
if (![login beginAuthorization]) {
NSLog(#"Failed to start authenticating.");
abort();
}
After you have logged in and gotten a session, you can do things like set your status message as follows:
AIMBuddyStatus * newStatus = [[AIMBuddyStatus alloc] initWithMessage:#"Using LibOrange on Mac!" type:AIMBuddyStatusAvailable timeIdle:0 caps:nil];
[session.statusHandler updateStatus:newStatus];
[newStatus release];
You can send messages to buddies like this:
AIMBlistBuddy * buddy = [[theSession.session buddyList] buddyWithUsername:buddyName];
[theSession.messageHandler sendMessage:[AIMMessage messageWithBuddy:buddy message:#"<BODY>Hello, world!</BODY>"]];
The library supports pretty much every standard feature that AIM users experience on a day to day basis. See my working example in MyTest.m. Note that it includes things other than the core functionality, such as thread blocking detection, etc.

I know Google is using OpenAIM in gTalk. You can find out more at: http://dev.aol.com/aim
GMail: http://www.google.com/support/chat/bin/answer.py?hl=en&answer=61024

Related

Philips Hue API: Remove application/username from bridge in order to start over

I'm using the HueSDK_iOS and everything seems to work fine.
I have one simple question for which I cannot seem to find a simple answer.
I want to test my app's functionality whenever a new user installs it.
I cannot find a proper way to de-authenticate my app from the bridge, so it will ask again to search for bridges etc and I can start over, to test everything.
I /did/ use :
cache = [PHBridgeResourcesReader readBridgeResourcesCache];
PHBridgeConfiguration *config = [cache bridgeConfiguration];
PHBridgeSendAPI *sendAPI = [[PHBridgeSendAPI alloc] init];
[sendAPI removeWhitelistEntryWithUsername:[config username] completionHandler:^(NSArray *errors) {
...
}];
and in the first time, it returns no errors, but I still am authenticated and can use the API , control lights etc, no notification arrives for disconnection or noLocalConnection.
If I run it again, I get an error: error = {\n address = \"/config/whitelist/_a_user_name\";\n description = \"resource, /config/whitelist/_a_user_name, not available\";\n type = 3;\n
(where a "_a_user_name" is the automatically generated username)
but I still keep being authenticated to the bridge.
So it seems it does delete the username from the whitelist, but still everything works as if I was authenticated.
So the question is simple: How do I remove my app from the bridge so I can start over and test all the steps? (Pushlinking etc)
It appears it is a bug in the bridge software as I was informed by Philips API support. They asked me to wait for an update.
According to this it can only be done through https://account.meethue.com/apps starting with API version 1.31.0.

Porting PHP API over to Parse

I am a PHP dev looking to port my API over to the Parse platform.
Am I right in thinking that you only need cloud code for complex operations? For example, consider the following methods:
// Simple function to fetch a user by id
function getUser($userid) {
return (SELECT * FROM users WHERE userid=$userid LIMIT 1)
}
// another simple function, fetches all of a user's allergies (by their user id)
function getAllergies($userid) {
return (SELECT * FROM allergies WHERE userid=$userid)
}
// Creates a script (story?) about the user using their user id
// Uses their name and allergies to create the story
function getScript($userid) {
$user = getUser($userid)
$allergies = getAllergies($userid).
return "My name is {$user->getName()}. I am allergic to {$allergies}"
}
Would I need to implement getUser()/getAllergies() endpoints in Cloud Code? Or can I simply use Parse.Query("User")... thus leaving me with only the getScript() endpoint to implement in cloud code?
Cloud code is for computation heavy operations that should not be performed on the client, i.e. handling a large dataset.
It is also for performing beforeSave/afterSave and similar hooks.
In your example, providing you have set up a reasonable data model, none of the operations require cloud code.
Your approach sounds reasonable. I tend to put simply queries that will most likely not change on the client side, but it all depends on your scenario. When developing mobile apps I tend to put a lot of code in cloud code. I've found that it speeds up my development cycle. For example, if someone finds a bug and it's in cloud code, make the fix, run parse deploy, done! The change is available to all mobile environments instantly!!! If that same code is in my mobile app, it really sucks, cause now I have to fix the bug, rebuild, push it to the app store/google play, wait x number of days for it to be approved, have the users download it... you see where I'm going here.
Take for example your
SELECT * FROM allergies WHERE userid=$userid query.
Even though this is a simple query, what if you want to sort it? maybe add some additional filtering?
These are the kinds of things I think of when deciding where to put the code. Hope this helps!
As a side note, I have also found cloud code very handy when needing to add extra security to my apps.

How to access an EKCalendar's `account` property

Take a look at the documentation for EKCalendar. It's pretty simple, it has five properties, only one of which is a string called title. Now if you have multiple calendars on your iPhone and you open iCal's Calendar settings, you can see that all calendars are nicely grouped by another string called account.
What I can't figure out, is how to do the same, because although you can see the account when you NSLog a EKCalendar instance, you can't access it:
EKCalendar <0x1851b0> {title = Work; type = CalDAV; account = some#addr.ess; allowsModify = YES; color = 0.690196 0.152941 0.682353 1.000000}
There is no account property, and trying to access the valueForKey:#"account" isn't working either, unsurprisingly.
So how do I get to that account property? Such a simple thing, driving me nuts! Help is much appreciated.
Update: since iOS 5.0, EKCalendar has a source property.
If you use class-dump on the iOS 4.3 (Simulator) SDK, you'll see that there's a read-only method -(id)accountName. However, since it's not in the headers, it's unfortunately private API and you can't use it if you want your App to be accepted in the App Store.
I recommend that you file an enhancement request with Apple requesting that this method be made public.
Though thinking about it: If you're really desperate, why not parse the output of -[EKCalendar description]? It's very very very bad style and it'll probably break in the future, but you might make it through the App Store review ;) In particular if you only use it for grouping and write your code extremely defensive so it doesn't break but simply doesn't group, should the output of the description method be formatted differently.
This information is not available in the 4.0 SDK. Have you looked at the developer previews of the forthcoming SDK to see if that might contain more information?
And on iOS6? It seems the private property [EKCalendar accountName] vanished. And [EKCalendar description] does not contain account anymore. :
EKCalendar <0x200f50e0> {title = test#gmail.com; type = Exchange; allowsModify = YES; color = #44A703;}
The [EKCalendar source] provides a EKSource object, that has a title but this is not the name I typed when I created the account but seems to be a more generic name, e.g. Exchange, Other, CalDAV.

Instant Messenger API

I need just a simple Objective-C app or API that can send and receive IMs to a single user.
BARE BONES.
I've looked at Skype, but the Objective-C part looks really outdated. AIM is preferred, but anything that can send and receive IMs is perfect.
Is there an API for this? For AIM or Skype?
Examples would be appreciated, and remember, I'm totally new to Obj-C.
I don't know about simple or bare bones, but Adium is a good open-source IM client for OS X written in Cocoa.
UDPATE: You might want to check out this blog post ("Towards an Open Source XMPP Framework for Cocoa"). It looks like the author wanted his own Jabber/XMPP Cocoa framework, too, and has even created a project for it in Google Code.
I am currently working on an Objective-C implementation of the OSCAR (AIM) protocol. It is being updated on GitHub. If I understand what you want to do correctly, the library, although incomplete, will meet your needs. It can send and receive messages, and work with status messages. It can also read the buddy list if you are interested in that. The entire library should be finished by the end of the month, and you can check it out on GitHub:
https://github.com/unixpickle/LibOrange
Signing on is this simple:
login = [[AIMLogin alloc] initWithUsername:username password:password];
[login setDelegate:self];
if (![login beginAuthorization]) {
NSLog(#"Failed to start authenticating.");
abort();
}
Once signed on, sending messages works like this:
AIMMessage * reply = [AIMMessage messageWithBuddy:[message buddy] message:#"Test"];
[theSession.messageHandler sendMessage:reply];
Obviously, you can check out the sample on GitHub, but I thought I would put that sample code to wet your appetite. Enjoy!
I don't know exactly how hard it would be to use, but isn't there an open source library for accessing IMs called libPurple? maybe you should check that out and see what it can do in Xcode.
If it's for a small scale deployment, it would be pretty easy to roll your own using Distributed Objects. I've heard it can be problematic trying to use DO for a high traffic Internet service though.

Obj-C server with multiple clients

I'm a fairly novice obj-c developer and have a question on how to set up a client-server relationship. I'm designing (mostly as a hobby) a board game to be played over the internet with friends and family (think monopoly). My problem: how do I set up the appropriate client-server relationship to have one server with multiple clients?
My thinking was to have one server contain all the information on the state of the game as well as send appropriate messages to a variety of objects through Cocoa's excellent distributed objects framework. However, I can't figure out how to have one server accept multiple clients.
firstConnection = [NSConnection defaultConnection];
[firstConnection setRootObject: firstPlayer];
[[NSRunLoop currentRunLoop] run];
But then what? Is there a way to tell the run loop to stop when a client is attached? I'd like to avoid multiple threading if possible as that would be a whole new complication to learn and this project is already challenging enough!
Any help would be greatly appreciated and I'd be happy to clarify anything at all if necessary.
Thanks in advance.
Basically the strategy to take is to have the server register itself as the root object. When the client connects to the server, it sends the server a connection message (defined by the server's protocol you create) that allows the server to register that client in order to send messages to it in the future. This could be as simple as adding the client to an array; no special run loops or threads should be needed.
Here's a quick example to communicate across processes, from a test app I wrote back when I was learning DO for the first time. Once the setup is done you can add code to make the server send messages to one or more objects in the _clients array based on any event you'd like, including setting up a timer for a rough game loop.
Server:
- (void)registerClient:(byref Client *)client;
{
[_clients addObject:client];
}
- (void)awakeFromNib;
{
_clients = [[NSMutableArray alloc] init];
[[NSConnection defaultConnection] setRootObject:self];
if ( [[NSConnection defaultConnection] registerName:#"server"] == NO )
{
// error code!
}
}
Client:
- (void)awakeFromNib;
{
id theProxy;
theProxy = [[NSConnection rootProxyForConnectionWithRegisteredName:#"server" host:nil] retain];
[theProxy setProtocolForProxy:#protocol(ServerP)];
if ( theProxy == nil )
// error code!
[theProxy registerClient:self];
}
Keep in mind that there are a lot of "gotchas" in distributed objects! Start simple, even if it means developing a rough prototype of your game idea first.
Cocoa's excellent distributed objects framework
That's the first time I've seen those words together like that ;)