{"id":28724187,"url":"https://github.com/processone/demo-xmpp-ios","last_synced_at":"2025-06-30T08:07:13.186Z","repository":{"id":35363014,"uuid":"39625835","full_name":"processone/demo-xmpp-ios","owner":"processone","description":"XMPPFramework Basic client relying using CocoaPods package","archived":false,"fork":false,"pushed_at":"2015-10-30T14:10:17.000Z","size":3652,"stargazers_count":56,"open_issues_count":6,"forks_count":27,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-06-15T10:09:25.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/processone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-24T10:17:00.000Z","updated_at":"2023-02-09T07:17:26.000Z","dependencies_parsed_at":"2022-09-17T12:01:31.311Z","dependency_job_id":null,"html_url":"https://github.com/processone/demo-xmpp-ios","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/processone/demo-xmpp-ios","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/processone%2Fdemo-xmpp-ios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/processone%2Fdemo-xmpp-ios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/processone%2Fdemo-xmpp-ios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/processone%2Fdemo-xmpp-ios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/processone","download_url":"https://codeload.github.com/processone/demo-xmpp-ios/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/processone%2Fdemo-xmpp-ios/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262736603,"owners_count":23356147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-15T10:09:24.259Z","updated_at":"2025-06-30T08:07:13.166Z","avatar_url":"https://github.com/processone.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# demo-xmpp-ios\n\n\n## Overview\n\n**XMPPFramework** Basic client relying using [Cocoapods](https://cocoapods.org) package.\n\n### I. Project setup\n1. Open Xcode and select *Create a new project*  \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/Capture%20d’écran%202015-07-22%20à%2011.15.32.png?raw=true =350x)\n2. Select *Single View Application* in the project editor  \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/Capture%20d’écran%202015-07-22%20à%2011.15.44.png?raw=true =350x)\n3. Fill all the required fields and then project location  \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/Swift_lang.png?raw=true =350x)\n4. Now quit Xcode, and open the terminal app    \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/Capture%20d’écran%202015-07-22%20à%2011.41.50.png?raw=true =350x)\n5. Navigate to your project directory and type `pod init` like so:  \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/Capture%20d’écran%202015-07-22%20à%2011.42.02.png?raw=true =350x)\n6. Edit the newly created *Podfile* by taping `emacs Podfile` (Feel free to use vim :)). It should look like this:  \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/Capture%20d’écran%202015-07-24%20à%2015.16.11.png?raw=true =350x)  \n*Press ctrl+x, ctrl+s to save, then ctrl+x, ctrl+c to end editing*\n\n7. Now Type `pod install` and wait for cocoapod to finish  \n![Xcode setup](https://github.com/processone/demo-xmpp-ios/blob/master/Setup%20resources/XMPPFramework_Swift_lang.png?raw=true =350x)  \nFrom now on you will have to open the xcworkspace file\n8. Open your `AppDelegate.h` and add the XMPP import:\n\n\t```Swift\n\t\timport XMPPFramework\n\t```\n\n#### Finito ! Build \u0026 run to confirm everyting is setup properly before going further\n\n\n\n### II.XMPP Demo\n1. Add the chat protocol at the top of your `AppDelegate`:\n\t```Swift\n\t\tprotocol ChatDelegate {\n\t\t\tfunc buddyWentOnline(name: String)\n\t\t\tfunc buddyWentOffline(name: String)\n\t\t\tfunc didDisconnect()\n\t\t}\n\t```\n1. Add the following degegates:\n\t```Swift\n\t\tXMPPRosterDelegate, XMPPStreamDelegate\n\t```\n1. Add XMPP properties:\n\t```Swift\n\t\tvar delegate:ChatDelegate! = nil\n\t\tlet xmppStream = XMPPStream()\n\t\tlet xmppRosterStorage = XMPPRosterCoreDataStorage()\n\t\tvar xmppRoster: XMPPRoster\n\n\t\toverride init() {\n\t\t\txmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)\n\t\t}\n\t```\n1. Still in `AppDelegate`, add a new method called `setupStream`, witch will be in charge of configuring the stream, roster and its storage:\n\t```Swift\n\t\tprivate func setupStream() {\n\t\t\txmppRoster.activate(xmppStream)\n\t\t\txmppStream.addDelegate(self, delegateQueue: dispatch_get_main_queue())\n\t\t\txmppRoster.addDelegate(self, delegateQueue: dispatch_get_main_queue())\n\t\t}\n\t```\n\tAnd call it in\n\t```Swift\n\t\tfunc application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -\u003e Bool\n\t```\n1. Implement the following methods:\n\t```Swift\n\t\tprivate func goOnline() {\n\t\t\tlet presence = XMPPPresence()\n\t\t\tlet domain = xmppStream.myJID.domain\n\n\t\t\tif domain == \"gmail.com\" || domain == \"gtalk.com\" || domain == \"talk.google.com\" {\n\t\t\t\tlet priority = DDXMLElement.elementWithName(\"priority\", stringValue: \"24\") as! DDXMLElement\n\t\t\t\tpresence.addChild(priority)\n\t\t\t}\n\t\t\txmppStream.sendElement(presence)\n\t\t}\n\n\t\tprivate func goOffline() {\n\t\t\tlet presence = XMPPPresence(type: \"unavailable\")\n\t\t\txmppStream.sendElement(presence)\n\t\t}\n\n\t\tfunc connect() -\u003e Bool {\n\t\t\tif !xmppStream.isConnected() {\n\t\t\t\tlet jabberID = NSUserDefaults.standardUserDefaults().stringForKey(\"userID\")\n\t\t\t\tlet myPassword = NSUserDefaults.standardUserDefaults().stringForKey(\"userPassword\")\n\n\t\t\t\tif !xmppStream.isDisconnected() {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif jabberID == nil \u0026\u0026 myPassword == nil {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\n\t\t\t\txmppStream.myJID = XMPPJID.jidWithString(jabberID)\n\n\t\t\t\tdo {\n\t\t\t\t\ttry xmppStream.connectWithTimeout(XMPPStreamTimeoutNone)\n\t\t\t\t\t\tprint(\"Connection success\")\n\t\t\t\t\t\treturn true\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tprint(\"Something went wrong!\")\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t}\n\n\t\tfunc disconnect() {\n\t\t\tgoOffline()\n\t\t\txmppStream.disconnect()\n\t\t}\n\t```\n1. Call `connect()` in `func applicationDidBecomeActive(application: UIApplication)` and `disconnect()` in `func applicationWillResignActive(application: UIApplication)`\n1. Now the last but not the least, implement the xmpp delegates:\n\t```Swift\n\t\tfunc xmppStreamDidConnect(sender: XMPPStream!) {\n\t\t\tdo {\n\t\t\t\ttry\txmppStream.authenticateWithPassword(NSUserDefaults.standardUserDefaults().stringForKey(\"userPassword\"))\n\t\t\t} catch {\n\t\t\t\tprint(\"Could not authenticate\")\n\t\t\t}\n\t\t}\n\n\t\tfunc xmppStreamDidAuthenticate(sender: XMPPStream!) {\n\t\t\tgoOnline()\n\t\t}\n\n\t\tfunc xmppStream(sender: XMPPStream!, didReceiveIQ iq: XMPPIQ!) -\u003e Bool {\n\t\t\tprint(\"Did receive IQ\")\n\t\t\treturn false\n\t\t}\n\n\t\tfunc xmppStream(sender: XMPPStream!, didReceiveMessage message: XMPPMessage!) {\n\t\t\tprint(\"Did receive message \\(message)\")\n\t\t}\n\n\t\tfunc xmppStream(sender: XMPPStream!, didSendMessage message: XMPPMessage!) {\n\t\t\tprint(\"Did send message \\(message)\")\n\t\t}\n\n\t\tfunc xmppStream(sender: XMPPStream!, didReceivePresence presence: XMPPPresence!) {\n\t\t\tlet presenceType = presence.type()\n\t\t\tlet myUsername = sender.myJID.user\n\t\t\tlet presenceFromUser = presence.from().user\n\n\t\t\tif presenceFromUser != myUsername {\n\t\t\t\tprint(\"Did receive presence from \\(presenceFromUser)\")\n\t\t\t\tif presenceType == \"available\" {\n\t\t\t\t\tdelegate.buddyWentOnline(\"\\(presenceFromUser)@gmail.com\")\n\t\t\t\t} else if presenceType == \"unavailable\" {\n\t\t\t\t\tdelegate.buddyWentOffline(\"\\(presenceFromUser)@gmail.com\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunc xmppRoster(sender: XMPPRoster!, didReceiveRosterItem item: DDXMLElement!) {\n\t\t\tprint(\"Did receive Roster item\")\n\t\t}\n\t```\n1. Let's add a `LoginViewController`, you are free to add whatever you want in this ViewController, but your `login` method should look like this:\n\t```Swift\n\t\t@IBAction func login(sender: AnyObject) {\n\t\t\tNSUserDefaults.standardUserDefaults().setObject(loginTextField.text!, forKey: \"userID\")\n\t\t\tNSUserDefaults.standardUserDefaults().setObject(passwordTextField.text!, forKey: \"userPassword\")\n\n\t\t\tlet appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate\n\n\t\t\tif appDelegate.connect() {\n\t\t\t\tdismissViewControllerAnimated(true, completion: nil)\n\t\t\t}\n\t\t}\n\t```\n1. It's nice to be connected, but it'll be even better if we could get our buddies list. Create a ```UITableViewController``` subclass and add ```Chatdelegate``` and an ivar ```var onlineBuddies = NSMutableArray()``` to store the buddy list\n1. Now set yourself as delegate for chat, then init your array in viewDidLoad:\n\n\t```Swift\n\t\tlet appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate\n\n\t\toverride func viewDidLoad() {\n\t\t\tsuper.viewDidLoad()\n\t\t\t// Do any additional setup after loading the view, typically from a nib.\n\t\t\tappDelegate.delegate = self\n\t\t}\n\t```\n1. Then in your viewwillappear, check if you are connected like so:\n\n\t```Swift\n\t\toverride func viewDidAppear(animated: Bool) {\n\t\t\tif (NSUserDefaults.standardUserDefaults().objectForKey(\"userID\") != nil) {\n\t\t\t\tif appDelegate.connect() {\n\t\t\t\t\tself.title = appDelegate.xmppStream.myJID.bare()\n\t\t\t\t\tappDelegate.xmppRoster.fetchRoster()\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tperformSegueWithIdentifier(\"Home.To.Login\", sender: self)\n\t\t\t}\n\t\t}\n\t```\n1. After that implement the chat delegates methods:\n\t```Swift\n\t\tfunc buddyWentOnline(name: String) {\n\t\t\tif !onlineBuddies.containsObject(name) {\n\t\t\t\tonlineBuddies.addObject(name)\n\t\t\t\ttableView.reloadData()\n\t\t\t}\n\t\t}\n\n\t\tfunc buddyWentOffline(name: String) {\n\t\t\tonlineBuddies.removeObject(name)\n\t\t\ttableView.reloadData()\n\t\t}\n\n\t\tfunc didDisconnect() {\n\t\t\tonlineBuddies.removeAllObjects()\n\t\t\ttableView.reloadData()\n\t\t}\n\t```\n1. The rest is pretty straightforward, you need to implement the `UITableView’s Delegates`:\n\t```Swift\n\t\toverride func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -\u003e UITableViewCell {\n\t\t\tlet cell = tableView.dequeueReusableCellWithIdentifier(\"CellIdentifier\", forIndexPath: indexPath)\n\n\t\t\tcell.textLabel?.text = onlineBuddies[indexPath.row] as? String\n\n\t\t\treturn cell\n\t\t}\n\n\t\toverride func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -\u003e Int {\n\t\t\treturn onlineBuddies.count\n\t\t}\n\n\t\toverride func numberOfSectionsInTableView(tableView: UITableView) -\u003e Int {\n\t\t\treturn 1\n\t\t}\n\t```\n1. Now if you want to send a message when the user tap on a row, implement this method:\n\t```Swift\n\t\toverride func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {\n\n\t\t\tlet alertController = UIAlertController(title: \"Warning!\", message: \"It will send Yo! to the recipient, continue ?\", preferredStyle: UIAlertControllerStyle.Alert)\n\t\t\t\talertController.addAction(UIAlertAction(title: \"Cancel\", style: UIAlertActionStyle.Cancel, handler: { (action) -\u003e Void in\n\t\t\t\talertController.dismissViewControllerAnimated(true, completion: nil)\n\t\t\t}))\n\n\t\t\talertController.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.Default, handler: { (action) -\u003e Void in\n\t\t\t\tlet message = \"Yo!\"\n\t\t\t\tlet senderJID = XMPPJID.jidWithString(self.onlineBuddies[indexPath.row] as? String)\n\t\t\t\tlet msg = XMPPMessage(type: \"chat\", to: senderJID)\n\n\t\t\t\tmsg.addBody(message)\n\t\t\t\tself.appDelegate.xmppStream.sendElement(msg)\n\t\t\t}))\n\t\t\tpresentViewController(alertController, animated: true, completion: nil)\n\t\t}\n\t```\n1. Build, run and start chatting with your friends !\n\n#### You can also download the sample project [here](https://github.com/processone/demo-xmpp-ios/archive/master.zip)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprocessone%2Fdemo-xmpp-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprocessone%2Fdemo-xmpp-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprocessone%2Fdemo-xmpp-ios/lists"}