question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Rendering][iOS] Not able to render images in adaptive cards on iOS

See original GitHub issue

Target Platforms

iOS

SDK Version

2.7.0, 2.8.1

Application Name

A Chat App

Problem Description

Context

We’re tying the AC Framework to display adaptive cards in a chat window to capture data from users. We tried with AdaptiveCards SDK versions 2.7.0 and 2.8.1

Issue, we can’t render images

Trying the framework we detected that the images we have on our adaptive cards weren’t rendered. All the components were rendered properly just the images are the ones that are not displayed.

We tried the example you created in the Readme file and were able to verify the same issue, the image you added in the example wasn’t displayed.

The expected behavior is to be able to render images in the adaptive cards.

Additional platform information

MacOS Monterey Version 12.0.1 Processor Quad-Core Intel Core i7 Xcode 13.2.1, Command line tools 13.2.1 Swift 5.5.2 Tested in Simulator and Device (Screenshots are of our actual device)

Screenshots

As you can see the adaptive card renders but the only element that was not displayed is the image.

WhatsApp Image 2022-01-14 at 19 48 41

The actions of the buttons worked as expected.

WhatsApp Image 2022-01-14 at 19 48 41 (1)

WhatsApp Image 2022-01-14 at 19 48 41 (2)

Card JSON

"{ \"type\": \"AdaptiveCard\", \"version\": \"1.0\", \"body\": [ { \"type\": \"Image\", \"url\": \"http://adaptivecards.io/content/adaptive-card-50.png\", \"horizontalAlignment\":\"center\" }, { \"type\": \"TextBlock\", \"horizontalAlignment\":\"center\", \"text\": \"Hello **Adaptive Cards!**\" } ], \"actions\": [ { \"type\": \"Action.OpenUrl\", \"title\": \"Learn more\", \"url\": \"http://adaptivecards.io\" }, { \"type\": \"Action.OpenUrl\", \"title\": \"GitHub\", \"url\": \"http://github.com/Microsoft/AdaptiveCards\" } ] }"

Sample Code Language

Swift

Sample Code

We created an iOS App project from start and added the code you added in the Readme file.

import UIKit
import SafariServices

class ViewController: UIViewController, ACRActionDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let jsonStr = "{ \"type\": \"AdaptiveCard\", \"version\": \"1.0\", \"body\": [ { \"type\": \"Image\", \"url\": \"http://adaptivecards.io/content/adaptive-card-50.png\", \"horizontalAlignment\":\"center\" }, { \"type\": \"TextBlock\", \"horizontalAlignment\":\"center\", \"text\": \"Hello **Adaptive Cards!**\" } ], \"actions\": [ { \"type\": \"Action.OpenUrl\", \"title\": \"Learn more\", \"url\": \"http://adaptivecards.io\" }, { \"type\": \"Action.OpenUrl\", \"title\": \"GitHub\", \"url\": \"http://github.com/Microsoft/AdaptiveCards\" } ] }";

        let cardParseResult = ACOAdaptiveCard.fromJson(jsonStr);
        if ((cardParseResult?.isValid)!) {
            let renderResult = ACRRenderer.render(cardParseResult!.card, config: nil, widthConstraint: 335);
            
            if (renderResult?.succeeded ?? false) {
                let ad = renderResult?.view;
                ad!.acrActionDelegate = (self as ACRActionDelegate);
                self.view.autoresizingMask = [.flexibleHeight];
                self.view.addSubview(ad!);
                ad!.translatesAutoresizingMaskIntoConstraints = false;
                
                NSLayoutConstraint(item: ad!, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0).isActive = true;
                NSLayoutConstraint(item: ad!, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1.0, constant: 3).isActive = true;
            }
        }
    }

    func didFetchUserResponses(_ card: ACOAdaptiveCard, action: ACOBaseActionElement) {
        if(action.type == ACRActionType.openUrl) {
            let url = URL.init(string:action.url());
            let svc = SFSafariViewController.init(url: url!);
            self.present(svc, animated: true, completion: nil);
        }
    }
}

Bridging Header

#ifndef AdaptiveCardsBridgingHeader_h
#define AdaptiveCardsBridgingHeader_h

#import "AdaptiveCards/AdaptiveCards.h"

#endif /* AdaptiveCardsBridgingHeader_h */

We added both recommendations you explained to enable image download

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSExceptionDomains</key>
		<dict>
			<key>adaptivecards.io</key>
			<dict>
				<key>NSExceptionAllowsInsecureHTTPLoads</key>
				<true/>
				<key>NSIncludesSubdomains</key>
				<true/>
			</dict>
		</dict>
	</dict>
	<key>UIApplicationSceneManifest</key>
	<dict>
		<key>UIApplicationSupportsMultipleScenes</key>
		<false/>
		<key>UISceneConfigurations</key>
		<dict>
			<key>UIWindowSceneSessionRoleApplication</key>
			<array>
				<dict>
					<key>UISceneConfigurationName</key>
					<string>Default Configuration</string>
					<key>UISceneDelegateClassName</key>
					<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
					<key>UISceneStoryboardFile</key>
					<string>Main</string>
				</dict>
			</array>
		</dict>
	</dict>
</dict>
</plist>

We tried also…

<key>NSAppTransportSecurity</key>
    <dict>
     <key>NSAllowsArbitraryLoads</key>
     <true/>
    </dict>

Zip with the demo project

AdaptiveCardsDemo.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:17
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jwoo-msftcommented, Jan 25, 2022

@jwoo-msft - is it required for an iOS host to hand-register resolvers for http/https/data? If so, that should be added to the docs. Alternatively, maybe we should register those by default?

(mentioning #6316 for doc tracking)

@paulcam206, this is documented, but I will move it to more prominent place.

2reactions
paulcam206commented, Jan 24, 2022

@jwoo-msft - is it required for an iOS host to hand-register resolvers for http/https/data? If so, that should be added to the docs. Alternatively, maybe we should register those by default?

(mentioning #6316 for doc tracking)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adaptive Card with Table not rendering on iOS mobile app
I sent message with Adaptive Card via Microsoft Bot Framework and it displayed correctly in MS Teams desktop version. But it couldn't render...
Read more >
Click on images in adaptive card is not triggering action ...
Click on images in the adaptive card is not triggering action on IOS devices despite its opening the image viewer. click is working...
Read more >
Troubleshooting Adaptive card rendering issue in iOS
Adaptive card will not render in iOS mobile teams in some cases. This video explains way to troubleshoot the same.
Read more >
Adaptive Cards
A whole new way to deliver UI. Adaptive Cards are platform-agnostic snippets of UI, authored in JSON, that apps and services can openly...
Read more >
Adaptive Card SKY Add-ins
In this post, I'll describe a new feature we've introduced - implementing "Adaptive Cards" within SKY Add-ins! This capability (in "Preview" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found