{"id":2126,"date":"2016-11-13T15:47:30","date_gmt":"2016-11-13T20:47:30","guid":{"rendered":"http:\/\/www.rexfeng.com\/blog\/?p=2126"},"modified":"2016-11-13T15:47:30","modified_gmt":"2016-11-13T20:47:30","slug":"how-to-open-phone-app-from-imessage-extension-and-pass-data","status":"publish","type":"post","link":"https:\/\/www.rexfeng.com\/blog\/2016\/11\/how-to-open-phone-app-from-imessage-extension-and-pass-data\/","title":{"rendered":"How to open phone app from iMessage extension and pass data"},"content":{"rendered":"<p>This weekend, I spent some time digging into iOS 10 iMessage app extensions.<\/p>\n<p>Creating an iMessage app or sticker pack is relatively easy. Here are a couple of resources for getting started: <a href=\"https:\/\/code.tutsplus.com\/tutorials\/create-an-imessage-app-in-ios-10--cms-26870\">tutsplus<\/a> and <a href=\"https:\/\/medium.com\/swift-programming\/learn-how-to-build-an-imessage-app-with-swift-7b106ce9b033\">medium<\/a>. Apple also\u00a0has their own <a href=\"https:\/\/developer.apple.com\/library\/content\/samplecode\/IceCreamBuilder\/Introduction\/Intro.html#\/\/apple_ref\/doc\/uid\/TP40017329-Intro-DontLinkElementID_2\">example iMessage app<\/a>.<\/p>\n<p>For a\u00a0new iMessage only app, you can choose <em>File &gt; New &gt; Project<\/em> and either &#8216;Sticker Pack Application&#8217; or &#8216;iMessage Application&#8217; in Xcode. To add an iMessage extension to your existing containing phone app, you can use <em>File &gt; New &gt; Target<\/em> and either &#8216;Sticker Pack Extension&#8217; or &#8216;iMessage Extension&#8217;.<\/p>\n<p>I wanted to understand the current state of user workflow between the iOS (main\/phone) app and the iMessage extension app. Apple has it&#8217;s work cut out for them. The iMessage App store is an awkward modal triggered from an individual iMessage conversation. Users seem to have\u00a0trouble locating the store and managing iMessage apps, so apps are getting bad reviews.<\/p>\n<p>The good news is that you can launch your phone app from the iMessage app.<\/p>\n<p>From the iMessage extension app, you can use this (with your own <em>AppName<\/em>):<\/p>\n<pre>guard let url: URL = URL(string: \"AppName:\/\/?myParam=myValue\") else { return }\r\n\r\nself.extensionContext?.open(url, completionHandler: { (success: Bool) in\r\n \r\n })<\/pre>\n<p>Calling the above code will open the phone app. One issue I ran into (under the extension scheme) is that the phone app will crash in the simulator when opened this way. Xcode shows\u00a0a SIGKILL since the iMessage app connected to Xcode is quit while the phone app is being opened. This appears to only be a simulator issue.<\/p>\n<p>You can access the URL params in your phone app&#8217;s App Delegate:<\/p>\n<pre class=\"p1\"><span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span><\/span><span class=\"s2\">func<\/span><span class=\"s1\"> application(<\/span><span class=\"s2\">_<\/span><span class=\"s1\"> app: <\/span><span class=\"s2\">UIApplication<\/span><span class=\"s1\">, open url: <\/span><span class=\"s2\">URL<\/span><span class=\"s1\">, options: [<\/span><span class=\"s2\">UIApplicationOpenURLOptionsKey<\/span><span class=\"s1\"> : <\/span><span class=\"s2\">Any<\/span><span class=\"s1\">] = [:]) -&gt; <\/span><span class=\"s2\">Bool<\/span><span class=\"s1\"> {<\/span>\r\n\r\n<span class=\"s3\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/span><span class=\"s1\">return<\/span> <span class=\"s1\">true<\/span>\r\n\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>}<\/span><\/pre>\n<p>The bad news is that you cannot launch your iMessage app from your phone app. Apple must have been short on time, as their usual modus operandi is to launch headline\u00a0features that are incomplete and hopefully iterate later if their business still cares. <a href=\"http:\/\/openradar.appspot.com\/28652170\">Radar(s) have been filed<\/a>.<\/p>\n<p><a href=\"https:\/\/forums.developer.apple.com\/thread\/50375\">When asked, &#8220;Is it possible for my app to open the Messages app with my iMessage extension activated?&#8221; An Apple Staff member\u00a0says, &#8220;There currently isn&#8217;t a way to do this.&#8221;<\/a><\/p>\n<p>I think opening your iMessage app from your phone app would be an excellent, natural use case. User does something in the containing app, then they want to share that app&#8217;s state with a friend using iMessage. Why rely on the user going to Messages, finding your iMessage app in the correct convo, and then recreating app state to send it over?<\/p>\n<p>So to recap, iMessage apps have a lot of potential as they are living apps within iMessages. <a href=\"http:\/\/tackmobile.com\/blog\/App-Groups-and-iMessage-Extensions-for-iOS-10.html\">They can communicate with their containing app<\/a>. But I have reservations about the UX, including discoverability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This weekend, I spent some time digging into iOS 10 iMessage app extensions. Creating an iMessage app or sticker pack is relatively easy. Here are a couple of resources for getting started: tutsplus and medium. Apple also\u00a0has their own example iMessage app. For a\u00a0new iMessage only app, you can choose File &gt; New &gt; Project [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1029],"tags":[965,1306,966,1307,1086],"class_list":["post-2126","post","type-post","status-publish","format-standard","hentry","category-programming","tag-app","tag-imessage","tag-ios","tag-message","tag-xcode"],"_links":{"self":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/2126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/comments?post=2126"}],"version-history":[{"count":5,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/2126\/revisions"}],"predecessor-version":[{"id":2131,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/2126\/revisions\/2131"}],"wp:attachment":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/media?parent=2126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/categories?post=2126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/tags?post=2126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}