{"id":1722,"date":"2013-07-31T07:55:54","date_gmt":"2013-07-31T03:55:54","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=1722"},"modified":"2013-07-31T08:16:20","modified_gmt":"2013-07-31T04:16:20","slug":"on-xmppframework-delegate-method-not-being-called","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=1722","title":{"rendered":"On XMPPFramework delegate method not being called"},"content":{"rendered":"<p>I have wasted some hours trying to understand, why a delegate method is not called and finally found solution. This is pretty common problem, as I&#8217;ve seen in the internet during a search, when I tried to resolve it. That is why I decided to write a little post on a solution. It is also pretty common problem, because a thing, that I discovered concerns not only XMPPFramework classes, but also many other similar classes.<\/p>\n<p>So, the reason of this problem is that most probably your class, that is a delegate for xmppStream and that contains xmppStream is actually released from memory or somehow becomes inactive. This problem occurs because in ARC everything that is created inside a method (and is not an instance variable) is released, when method finishes. And delegate methods cannot be called, that are invoked by some other background process. <\/p>\n<p>I have a class, called EjabberdRegistrator, it contains XMPPStream as a property and it is a delegate of this XMPPStream. <\/p>\n<pre>\r\n@property (strong, nonatomic) XMPPStream *xmppStream;\r\n\r\n- (XMPPStream *)xmppStream\r\n{\r\n    if ( _xmppStream == nil ) {\r\n        \r\n        _xmppStream = [[XMPPStream alloc] init];\r\n        [_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];\r\n        \r\n    }\r\n    \r\n    return _xmppStream;\r\n}\r\n<\/pre>\n<p>This is how I was initializing this class: <\/p>\n<pre>\r\nEjabberdRegistrator *ejabberdRegistrator = [[EjabberdRegistrator alloc] init];\r\n[ejabberdRegistrator registerClientWithInfo:clientInfo delegate:self];\r\n<\/pre>\n<p>Because ejabberdRegistrator instance is not used anywhere inside a method where it was created, it was released by ARC after method was finished, despite the fact, that xmppStream was still working. That is why xmppStream delegate method was not called. <\/p>\n<p>After some thoughts I finally discovered this and made my ejabberdRegistrator instance a property and created it like this: <\/p>\n<pre>\r\n- (IBAction)signInClicked:(id)sender\r\n{\r\n    ClientInfo *clientInfo = [[ClientInfo alloc] init];\r\n    clientInfo.roughPhoneNumber = _loginField.text;\r\n    \r\n    self.ejabberdRegistrator = [[EjabberdRegistrator alloc] init];\r\n    [self.ejabberdRegistrator registerClientWithInfo:clientInfo delegate:self];\r\n}\r\n<\/pre>\n<p>This worked! So, it is very important to make a class, that is a delegate of some other class, that is contained inside it make persistent from releasing from memory.<\/p>\n<p>Note that this also can be achieved by creating shared instance of that class using dispatch_once.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have wasted some hours trying to understand, why a delegate method is not called and finally found solution. This is pretty common problem, as I&#8217;ve seen in the internet during a search, when I tried to resolve it. That is why I decided to write a little post on a solution. It is also [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1722","post","type-post","status-publish","format-standard","hentry","category-ios"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>On XMPPFramework delegate method not being called - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=1722\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"On XMPPFramework delegate method not being called - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"I have wasted some hours trying to understand, why a delegate method is not called and finally found solution. This is pretty common problem, as I&#8217;ve seen in the internet during a search, when I tried to resolve it. That is why I decided to write a little post on a solution. It is also [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=1722\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2013-07-31T03:55:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-07-31T04:16:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"On XMPPFramework delegate method not being called\",\"datePublished\":\"2013-07-31T03:55:54+00:00\",\"dateModified\":\"2013-07-31T04:16:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722\"},\"wordCount\":286,\"commentCount\":2,\"articleSection\":[\"iOS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722\",\"name\":\"On XMPPFramework delegate method not being called - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2013-07-31T03:55:54+00:00\",\"dateModified\":\"2013-07-31T04:16:20+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1722#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"On XMPPFramework delegate method not being called\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"On XMPPFramework delegate method not being called - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=1722","og_locale":"en_US","og_type":"article","og_title":"On XMPPFramework delegate method not being called - Denis Kutlubaev","og_description":"I have wasted some hours trying to understand, why a delegate method is not called and finally found solution. This is pretty common problem, as I&#8217;ve seen in the internet during a search, when I tried to resolve it. That is why I decided to write a little post on a solution. It is also [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=1722","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2013-07-31T03:55:54+00:00","article_modified_time":"2013-07-31T04:16:20+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=1722#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=1722"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"On XMPPFramework delegate method not being called","datePublished":"2013-07-31T03:55:54+00:00","dateModified":"2013-07-31T04:16:20+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=1722"},"wordCount":286,"commentCount":2,"articleSection":["iOS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=1722#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=1722","url":"https:\/\/blog.alwawee.ru\/?p=1722","name":"On XMPPFramework delegate method not being called - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2013-07-31T03:55:54+00:00","dateModified":"2013-07-31T04:16:20+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=1722#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=1722"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=1722#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"On XMPPFramework delegate method not being called"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/1722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1722"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/1722\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}