{"id":177,"date":"2015-04-16T07:42:17","date_gmt":"2015-04-16T05:42:17","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=177"},"modified":"2021-11-27T16:04:57","modified_gmt":"2021-11-27T15:04:57","slug":"change-controller-on-application-background","status":"publish","type":"post","link":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/","title":{"rendered":"Objective-C: Change controller on application background"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Yes, you can!<br>Now you are able to change the snapshot of your app while is in background!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An example here:<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"[Objective-C] Change ViewController on applicationWillResignActive\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/MrTF2k9ptZQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-red-background-color has-vivid-red-color\"\/>\n\n\n\n<h5 class=\"wp-block-heading\">How to?<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Make a new project, and in your\u00a0<strong>AppDelegate.m<\/strong>, consider the system methods:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-\u00a0(void)applicationWillResignActive:(UIApplication\u00a0*)application\u00a0{\n    \/\/ to add your background controller\n    &#91;self applySnapshot];\n}\n\n-\u00a0(void)applicationDidBecomeActive:(UIApplication\u00a0*)application\u00a0{\n    \/\/ to remove your background controller\n    &#91;self removeSnapshot];\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, add in&nbsp;<strong>applicationWillResignActive<\/strong>&nbsp;method the \u201c<em>applySnapshot<\/em>\u201d and then call \u201c<em>removeSnapshot<\/em>\u201d to remove it in&nbsp;<strong>applicationDidBecomeActive<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Method\u00a0<em>applySnapshot<\/em>, make a screenshot of your screen and next apply to the captured image, the\u00a0<strong>CIGaussianBlur<\/strong>\u00a0filter to show you the blur effect.<br>At the bottom of the method there is an image array animated, just to show you the potentiality!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-(void)applySnapshot {\n\tCGRect rect = &#91;&#91;UIScreen mainScreen] bounds];\n\tUIGraphicsBeginImageContext(rect.size);\n\t&#91;self.window.layer renderInContext:UIGraphicsGetCurrentContext()];\n\tUIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();\n\tUIGraphicsEndImageContext();\n\n\tCIImage *imageToBlur = &#91;CIImage imageWithCGImage:viewImage.CGImage];\n\tCIFilter *gaussianBlurFilter = &#91;CIFilter filterWithName: @\"CIGaussianBlur\"];\n\t&#91;gaussianBlurFilter setValue:imageToBlur forKey: @\"inputImage\"];\n\t&#91;gaussianBlurFilter setValue:&#91;NSNumber numberWithFloat: 2] forKey: @\"inputRadius\"];\n\tCIImage *resultImage = &#91;gaussianBlurFilter valueForKey: @\"outputImage\"];\n\n\tviewImage = &#91;&#91;UIImage alloc] initWithCIImage:resultImage];\n\n\tUIImageView *newView = &#91;&#91;UIImageView alloc] initWithFrame:rect];\n\tnewView.image = viewImage;\n\tnewView.tag = 1234;\n\tnewView.alpha = 0;\n\n\tUIImageView *imgv = &#91;&#91;UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];\n\timgv.animationImages = @&#91;\n\t\t&#91;UIImage imageNamed:@\"1\"],\n\t\t&#91;UIImage imageNamed:@\"2\"],\n\t\t&#91;UIImage imageNamed:@\"3\"]\n\t];\n\timgv.animationDuration = 3;\n\t&#91;imgv startAnimating];\n\n\t&#91;newView addSubview:imgv];\n\n\t&#91;self.window addSubview:newView];\n\t&#91;self.window bringSubviewToFront:newView];\n\n\t&#91;UIView animateWithDuration:0.25 animations:^{\n\t\tnewView.alpha = 1;\n\t}];\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>- (void) removeSnapshot {\n\tUIView *colourView = &#91;self.window viewWithTag:1234];\n\t&#91;UIView animateWithDuration:0.25 animations:^{\n\t\tcolourView.alpha = 0;\n\t} completion:^(BOOL finished) {\n\t\t&#91;colourView removeFromSuperview];\n\t}];\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Have fun!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes, you can!Now you are able to change the snapshot of your app while is in background! An example here:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[11,2],"tags":[161,162,163,164,165,166,138,167,168],"class_list":["post-177","post","type-post","status-publish","format-standard","hentry","category-mobile","category-objectivec","tag-applicationdidbecomeactive","tag-applicationwillresignactive","tag-background","tag-cifilter","tag-cigaussianblur","tag-ciimage","tag-iphone","tag-objectivec","tag-snapshot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Objective-C: Change controller on application background - while (true) {\u00a0}<\/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:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Objective-C: Change controller on application background - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"Yes, you can!Now you are able to change the snapshot of your app while is in background! An example here:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-16T05:42:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-27T15:04:57+00:00\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\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:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"Objective-C: Change controller on application background\",\"datePublished\":\"2015-04-16T05:42:17+00:00\",\"dateModified\":\"2021-11-27T15:04:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/\"},\"wordCount\":114,\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"keywords\":[\"applicationDidBecomeActive\",\"applicationWillResignActive\",\"background\",\"CIFilter\",\"CIGaussianBlur\",\"CIImage\",\"iPhone\",\"objectivec\",\"snapshot\"],\"articleSection\":[\"mobile\",\"objectivec\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/\",\"name\":\"Objective-C: Change controller on application background - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"datePublished\":\"2015-04-16T05:42:17+00:00\",\"dateModified\":\"2021-11-27T15:04:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/change-controller-on-application-background\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Objective-C: Change controller on application background\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Objective-C: Change controller on application background - while (true) {\u00a0}","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:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/","og_locale":"en_US","og_type":"article","og_title":"Objective-C: Change controller on application background - while (true) {\u00a0}","og_description":"Yes, you can!Now you are able to change the snapshot of your app while is in background! An example here:","og_url":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2015-04-16T05:42:17+00:00","article_modified_time":"2021-11-27T15:04:57+00:00","author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/#article","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/"},"author":{"name":"Alberto Pasca","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"Objective-C: Change controller on application background","datePublished":"2015-04-16T05:42:17+00:00","dateModified":"2021-11-27T15:04:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/"},"wordCount":114,"publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"keywords":["applicationDidBecomeActive","applicationWillResignActive","background","CIFilter","CIGaussianBlur","CIImage","iPhone","objectivec","snapshot"],"articleSection":["mobile","objectivec"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/","url":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/","name":"Objective-C: Change controller on application background - while (true) {\u00a0}","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website"},"datePublished":"2015-04-16T05:42:17+00:00","dateModified":"2021-11-27T15:04:57+00:00","breadcrumb":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.albertopasca.it\/whiletrue\/change-controller-on-application-background\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"Objective-C: Change controller on application background"}]},{"@type":"WebSite","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website","url":"https:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=177"}],"version-history":[{"count":5,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":3059,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/177\/revisions\/3059"}],"wp:attachment":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}