Button/Link inside UILabel to switch to another ViewController - ios

I want to show some Facebook posts inside my iOS app. I get the whole post as a JSON-object from the Graph API. Works pretty fine.
So, if a user makes a new post and tags any page inside this post, the user-id (or page-id) is also included in that JSON object, giving me the offset and length inside the text, which should link to that page. (Sounds weird, so let me give you an example):
{
"id": "135416986571191_709831435796407",
"from": {
"category": "Musician/band",
"name": "DANNIC",
"id": "135416986571191"
},
"to": {
"data": [
{
"category": "Musician/band",
"name": "Tom & Jame",
"id": "423531801036780"
},
{
"category": "Record label",
"name": "Revealed Recordings",
"id": "104563552952573"
}
]
},
"message": "Wait For You (Tom & Jame Remix) is coming out in 2 days on Revealed Recordings!",
"message_tags": {
"14": [
{
"id": "423531801036780",
"name": "Tom & Jame",
"type": "page",
"offset": 14,
"length": 10
}
],
"59": [
{
"id": "104563552952573",
"name": "Revealed Recordings",
"type": "page",
"offset": 59,
"length": 19
}
]
},
"picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xfa1/v/t15.0-10/10876067_709831642463053_709831435796407_64260_924_b.jpg?oh=49c825ff152d98de125820093b5cff05&oe=5551397E&__gda__=1431085295_7c41923cf64cc0946a39e85b705ee691",
....
....
As you can see, there is the "message_tags", which contains two page-ids, the name and offset and length. I want to replace the text in the "message" with a UIButton or just a link to that page. How can I do that?
Here is a screenshot of that post how it looks inside the Facebook App:
As you can see, the "Tom & Jame" is clickable and the rest (except "Revealed Recordings") is normal text. If you tap on 'Tom & Jame' it will switch to another View Controller showing the page of them. That's exactly what I want inside my app.
I know I could use an NSAttributedText for my label, and use the NSLinkAttributedName to make the text clickable. But I don't want my app to switch to safari and open the facebook page, I want to stay inside my app and just switch to another UIViewController, showing the infos of that page etc.
Can I use my app's url scheme for that link, even though I stay inside my app? Or can I put a UIButton inside that label and handle the tap inside my view controller?
Whats the best solution for that? Any help is appreciated! :)

What I would do is put the text in a UITextView and use NSAttributedText. I would construct the URLs in a manner that I could parse later (just enough to get UITextView to render a link, but it doesn't have to be a real URL on facebook).
Then I would override shouldInteractWithURL which is sent to the delegate of UITextView. Here, I could re-parse the URL, retrieve the data, and load my subsequent view controller.
Take a look at the reference here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITextViewDelegate/textView:shouldInteractWithURL:inRange:

Related

Slack API chat.postMessage URL Unfurling

I have a bot app that sends a message to the slack channel. I am using https://api.slack.com/methods/chat.postMessage/ to send messages to the slack channel.
My message sometimes has few links (GIF) which are being rendered in the channel as a plain link.
I want them to be unfurled so that it can display animated GIF on the channel itself.
I tried passing unfurl_links: true to the API parameter however it doesn't work.
Here is my JSON payload
{
"text": "Anniversary Alert :confetti_ball:",
"channel": "C01AGGP63ST",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Anniversary Alert :confetti_ball:\n\nLet's all take a moment to congratulate <#U024FCGPW> on their 10 year anniversary!\n\nWe wish you a very happy anniversary and many more great years ahead with us.\n\nhttps://media0.giphy.com/media/1yjpDZgvGkb6nTynq3/giphy.gif?cid=cbd9d2f95475c686b1a293a6cf43de5f3f640e4eb012f714&rid=giphy.gif"
}
}
],
unfurl_links: true
}
Can someone please help?
Used "attachments" property of the API payload and it unfurls the link
{
"text": "Anniversary Alert :confetti_ball:",
"channel": "C01AGGP63ST",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Anniversary Alert :confetti_ball:\n\nLet's all take a moment to congratulate <#U024FCGPW> on their 10 year anniversary!\n\nWe wish you a very happy anniversary and many more great years ahead with us.\n\nhttps://media0.giphy.com/media/1yjpDZgvGkb6nTynq3/giphy.gif?cid=cbd9d2f95475c686b1a293a6cf43de5f3f640e4eb012f714&rid=giphy.gif"
}
}
],
"attachments": [
{
"text": "",
"image_url": "https://media0.giphy.com/media/1yjpDZgvGkb6nTynq3/giphy.gif?cid=cbd9d2f95475c686b1a293a6cf43de5f3f640e4eb012f714&rid=giphy.gif"
}
]
}
The big gotcha here is that slack unfurl is only triggered when it's a user (bots do not trigger unfurls). Too bad - I'm running into the same issue - unfurl was going to be the way to go but I missed the fine print. I think I'm going to just go with a chat threaded reply (which is way less pretty).

How to have a standard block kit interactive component look like a modal input

I'm building a modal that has several select inputs on it. The values entered get posted to my server when the user clicks the modal submit button. However, for one of the selects I need it to post to the server immediately when the user interacts with it - and from what I understand, inputs don't do this.
So, I'm using an "Actions" layout block for one of the static select elements. However, the select looks nothing like the equivilent input static select. It's smaller and doesn't fill the full width of the video. Is there any way to do this?
You can use an input staticSelect and set the dispatchAction to true
{
"dispatch_action": true,
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "Label",
"emoji": true
}
}
this works for the staticSelect as well

rest/api/2/issue/<issue-id>/transitions returns empty array

I've created an issue that follows this workflow:
When I call rest/api/2/issue/<issue-id>/transitions after creating an issue (which is in OPEN status now) it returns the following JSON:
{
"expand": "transitions",
"transitions": [
{
"id": "4",
"name": "Start Progress",
"to": {
"self": "URL",
"description": "This issue is being actively worked on at the moment by the assignee.",
"iconUrl": "URL",
"name": "In Progress",
"id": "3",
"statusCategory": {
"self": "URL",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"fields": {}
}
]
}
When I make the same call after I change the issue status to "IN PROGRESS" I get back
{
"expand": "transitions",
"transitions": []
}
My questions are:
In the first response shown above, I expected the transitions to "CLOSED" and "RESOLVED" along with the one to "IN PROGRESS". But I only get back the one leading to "IN PROGRESS". Why?
I expected the second response to contain the transitions to "CLOSED", "RESOLVED" and "OPEN", but it returns an empty array. Why?
Please explain the responses from this API
What call should I make to get the next possible transitions?
This is probably a permission issue. The API only shows the transitions that are available to the current user, thus if you are not allowed to execute the CLOSE or RESOLVE transitions due to conditions in the project workflow, they will not appear in the JSON object.
See getTransitions from the JIRA REST API :
Get a list of the transitions possible for this issue by the current user, along with fields that are required and their types.
In order to get the transitions, you can either log in with an account that has the required permissions (check the corresponding workflow) or modify the conditions of the transition in this workflow.

Error in Google SDTT: "All values provided for url must point to the same page."

I am trying to create some JSON-LD structured data for a list of products on an ecom-site but I am getting an error when using Google's Structured Data Testing Tool.
So far, I have this:
{
"#context": "http://schema.org",
"#type": "OfferCatalog",
"name": "Fresh Fruit",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item":
{
"#type": "Offer",
"price": "1.20",
"priceCurrency": "GBP",
"availability": "http://schema.org/InStock",
"url": "http://example.com/green-apples/",
"itemOffered": {
"#type": "Product",
"name": "Green Apples",
"url": "http://example.com/green-apples/"
}
}
}
]
}
Mostly it validates, but the Google tool throws the following error:
All values provided for url must point to the same page.
The error highlights line 11 ("#type": "Offer",).
The URL fields seem to be clashing with the #context declaration, because if I change the context to either a non-url string or http://example.com, it validates (although, this obviously causes its own issues). (This has been shown to be a red-herring, in the comments below)
What am I missing here? It feels like something blindingly obvious.
I think it is connected with pushing of accelerated mobile pages and its structured data.
Please check my thoughts here: All values provided for URL must point to the same page. My guess was about the problem in Google’s SDTT
So, to fix the problem with your structure data, please use the correct version of ItemList (there are Separately and Combined marked up ItemLists, please check here):
If your items are on the same page, please use the version with items
inside, the Combined one.
Otherwise, if you point to different pages inside and your items are
not on one page, please DON’T put item element with type and other
description inside, the Separately marked up one.
Now it's 2018.
Answer by Yash Pal above is close, but not quite right.
This is not an error from Google validator tools.
The error is valid and you need to fix it.
You use the "Single Page" approach ( there are two approaches "Summary page" and "Single page" )
For "Single Page" approach, you need each URL to be exactly same, and each of them should have "an anchor".
The Google developer doc clearly mentioned it.
I wrote the explanation details there
If your page contains some links to another page, then you should use "Summary Page" approach and it had different data structure ( much simpler one, I think )
I think the issues occurs when we mix two list types i.e Summary page + multiple full details pages and A single, all-in-one-page list.
Google stated on page - https://developers.google.com/search/docs/guides/mark-up-listings
If this is a summary page, the ListItem should include only the type,
position, and url properties.
If this is an all-in-one-page list, the ListItem should include all the additional schema.org properties for the data type that it describes (for example, Recipe or Course objects).
But Google should consider eCommerce category's product listing where people display numbers of product with more than 3 properties on summery page and these are obvious for eCommerce, like price and image are 2 important item on product listing page except the 3 listed above.
So we need to raise this issue with Google to address the concern.
No, it is NOT an error in Google's SDTT,
I have helped many people fix their structured data, including dynamic arrays. Read the instructions. Google clearly states "All values for the URL must point to the same page". Think about it, Google is trying to tell you something.
That something means this "Hey you are using a different item list from the example we provided, your item list has more than two item".
The solution:
Use anchors! Voila!
Please use this example snippet and you cannot go wrong. And another tip; use the Fetch Url option from SDTT:
<script type="application/ld+json">
/*structerd data markup compiled by http://www.iwanross.co.za */
{
"#context": "http://schema.org",
"#type": "ItemList",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item": {
"#type": "Recipe",
"url": "https://www.smokingchimney.com/#beetroot",
"name": "Beetroot Side Salad for the braai",
"image": "http://www.smokingchimney.com/recipe-pages/images/1x1/Beetroot-Salad-
for-the-Braai-800x451.jpg",
"author": {
"#type": "Person",
"name": "Marna Ross"
},
"datePublished": "2018-10-05"
}
},
{
"#type": "ListItem",
"position": 2,
"item": {
"#type": "Recipe",
"url": "https://www.smokingchimney.com/#carrot",
"name": "Carrot Cake",
"image": "http://www.smokingchimney.com/recipe-pages/images/16x9/carrot-cake-
recipe-picture-1024x576.jpg",
"author": {
"#type": "Person",
"name": "Marna Ross"
},
"datePublished": "2018-10-05"
}
},
{
"#type": "ListItem",
"position": 3,
"item": {
"#type" : "Recipe",
"url":"https://www.smokingchimney.com/#overnight",
"name": "Overnight Steak Marinade",
"image": "http://www.smokingchimney.com/recipe-pages/images/1x1/Overnight-steak-
marinade-700x465.png",
"author": {
"#type": "Person",
"name": "Marna Ross"
},
"datePublished": "2009-10-05"
}
}
]
}
</script>
It is surely an error in the validator. I checked with the examples google provided: https://developers.google.com/search/docs/guides/mark-up-listings .
If you click on the 2nd example you will see that it has the same error.
The error is shown even if you use 1 item:
{
"#context": "http://schema.org",
"#type": "ItemList",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item": {
"#type": "Recipe",
"url": "http://example.com/desserts/pies/#apple-pie",
"name": "Apple Pie",
"image": "https://example.com/300px-Apple_pie.jpg",
"author": {
"#type": "Person",
"name": "Carol Smith"
},
"datePublished": "2009-11-05"
}
}
]
}
you don't need to anchor every URL, you can add parameters to the URL as well ?i=1
like:
https://website.com/d/link?i=1
https://website.com/d/link?i=2
....
Use type OfferCatalog instead of ItemList. https://schema.org/OfferCatalog

Slack - how to post a link to network folder?

I'm using a webhook to post messages to Slack via PowerShell script and I'd like to include a link to a network folder. I was able to do it with
<file://server/folder|files>
however when the generated 'files' link is clicked nothing happens. Is there a way to specify target so that a clicked link opens in a new window? If I copy the generated link and paste it into the browser, the index is rendered just fine and that would be sufficient for my purposes. Are there any alternative solutions?
You may have some success with Slack's Link Buttons, which specifically open links in new browser tabs when clicked.
{
"text": "Test Link Buttons",
"channel": "C061EG9SL",
"attachments": [
{
"fallback": "Test link button to file://server/folder",
"actions": [
{
"type": "button",
"name": "file_request_123456",
"text": "Test",
"url": "file://server/folder",
"style": "primary",
"confirm": "Really?"
}
]
}
]
}
Slack Message Builder example

Resources