UGC Techdocs
  • Introduction
  • Guides
    • Analytics
      • Tracking UGC on Adobe Analytics
      • Tracking Widget interactions with Google Analytics
    • Direct Uploader
      • How to add Custom Data to Direct Uploader
      • How to capture Custom Data on Direct Uploader
      • How to automatically tag data on Direct Uploader
      • How to Customize error messages on Direct Uploader
      • How to Track Direct Uploader form submissions with Google Analytics (Universal & GA 4)
    • Data Templates
      • Creating a Data Template
    • Rights via Registration
      • Capture Custom Data on Rights by Registration Form
      • Styling Rights via Registration Form
    • REST API
      • Caching REST API results for optimization
      • Posting content into Nosto via Tile API
      • Posting images into Nosto via Tile API
    • Onsite Widgets (2.0)
      • Blank Canvas
        • How to Use the Blank Canvas to Create a Twitter Count Widget
        • Creating an Auto-Scrolling Carousel using Blank Canvas
        • Creating Gallery Widget by Using the Blank Canvas Widget
        • Creating a simple Hover effect using Blank Canvas
        • Creating a Word Cloud using Blank Canvas
        • Creating Your Widget by Using the Blank Canvas
      • Bind your own Events
      • Creating a Grid Widget from Waterfall
      • Create a Q&A Widget using Data Templates
      • Displaying a Widget in a Mobile App
      • Dynamically Specify Products to Display in Widget
      • Dynamically specify what Tile to display in a Widget
      • How to add a title / subtitle to a widget
      • How to localize the load more button on widgets
      • How to overlay existing Google Map with the UGC Map Widget
      • Styling cross-sellers on Grid and Carousel Widgets
      • How to Load External JS and CSS into Widgets
      • Profiling Widget Performance
      • Re-targeting with Widgets and Facebook Pixel
      • Render Widget filters dynamically
      • Styling Carousel Widget
      • Styling Grid Widget
      • Styling Masonry Widget
      • Styling Waterfall Widget
      • Styling Widget Expanded Tile
      • Styling Widget Shopspots
      • Using Web Fonts in Widgets
    • Digital Screens
      • Customizing Carousel Event Screen
      • Customizing Mosaic Event Screen
      • Customizing Scrollwall Event Screen
      • Customizing the Mosaic Event Screen to Have 9 Even Tiles
    • Email
      • Adding Location to an Email Tile
      • Styling the Email Widget
    • Integrations
      • DoubleClick
        • UGC Ads with Nosto and Google DoubleClick
      • Zapier
        • Consuming UGC Webhooks via Zapier
      • Mailchimp
        • Bring Social Content into a Mailchimp Campaign
    • Webhooks
      • Trigger notifications when content is in the moderation queue
  • Widgets
  • API Docs
    • JavaScript API
      • Widgets
        • Introduction
        • API Reference for Content Widgets
        • API Reference for Blank Canvas
        • API Reference for Map Widget
      • Digital Screens
        • Introduction
        • API Reference
    • Content API
      • Reference
    • REST API
      • Reference
        • Filters API
        • Moderation Views API
        • Tags API
        • Terms API
        • Tiles API
        • Users API
        • Widgets API
        • Automation Rules API
        • REST API Reference Widgets style and config
      • Best Practices
    • Webhooks
  • Enterprise Tools
    • Automation Rules
      • Triggers
      • Actions
      • Samples
    • Data Templates
    • User Access Control (UAC)
    • Single Sign On (SSO)
    • Enterprise Admin User Interface (EAUI)
    • Zapier
  • Commerce Tools
    • Product Feeds
    • Widget Implementation
    • Reporting
    • Integrations
      • Google Tag Manager
      • Magento
      • SalesForce Commerce Cloud
      • Shopify
      • Shopify Add To Cart
        • Global Variant Mapping for Add to Cart
        • Customise Add to Cart Widget Experience
  • Analytics
    • Google Analytics 4
      • Getting Started
      • Widgets Events
      • E-commerce Events
      • Email Events
  • Terms of Use
Powered by GitBook
On this page
  • Overview
  • Key Concepts
  • Parent Page
  • Android Studio
  • XCode
  • Requirements
  • The Fun Part
  • Configure your Widget Parent Page
  • Add WebView to your iOS Mobile App
  • Add WebView to your Android Mobile App
  • Best Practices for Web Apps
  • Summary and Next Steps

Was this helpful?

  1. Guides
  2. Onsite Widgets (2.0)

Displaying a Widget in a Mobile App

PreviousCreate a Q&A Widget using Data TemplatesNextDynamically Specify Products to Display in Widget

Last updated 1 year ago

Was this helpful?

Overview

In this guide we explore the general concept of displaying a Nosto's UGC Widget into within an Android and iOS Mobile Application. This will enable you to render social media content inside of your app without a lot of hassle.

This guide focuses on the simplest and effective way of displaying the Widget through the use of WebViews.

Key Concepts

Parent Page

The page which will host the embedded UGC Widget and will be referenced by the relevant mobile app web view.

Android Studio

Android Studio is an integrated development environment (IDE) for developing on the Android platform.

XCode

XCode is an integrated development environment (IDE) for developing on the iOS platform.

Requirements

To ensure our widgets function correctly, they must have access to the DOM. You can enable DOM Storage in your web view by following the instructions at this

The Fun Part

In this guide we will do the following:

  • Configure your Widget Parent Page

  • Configure WebView on an iOS Mobile App via XCode

  • Configure WebView on an Android Mobile App via Android Studio

Configure your Widget Parent Page

Your Parent Page will be the hosted page that will contain your Embedded UGC Widget.

For the purposes of this guide, it is assumed that either a Fluid Horizontal or Fluid Vertical Widget will be used.

In order to ensure your Widget renders correctly when referenced from your Mobile Application it is important that you include the following META information in your page header.

<head>
    <meta name="apple-mobile-web-app-capable" content="YES"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"/>
    <meta name="HandheldFriendly" content="true"/>
</head>

This information will tell the WebView the scale of the page, that it has been optimised for handheld devices and in the case of iOS that it is Apple Mobile App Capable.

The second step is ensure that there is no unnecessary padding or white space around your Widget. To remove this, please include the following CSS on your parent page:

<style>
    body {
        padding: 0;
        margin: 0;
    }
    body,
    .stacklahfw,
    .stacklahfw iframe {
        max-width: 100%;
    }
</style>

This CSS will remove the default padding that exists on all HTML pages, as well renders the UGC Widget at 100% the page width.

Add WebView to your iOS Mobile App

For the purpose of this guide, we will create a brand new iOS Mobile Application on XCode.

Create a New Application with the following attributes:

  • Template: Single View Application

  • Application Name: WebView

  • Language: Objective-C

  • Devices: Universal

  • Storyboards: True

And select where you would like to save the application files on your computer.

Once setup you will notice on there left there will be a series of pre-generated files. These files will be called AppDelegate, ViewController and Main.Storyboard.

Both AppDelegate and ViewController will have a .h and .m version of the file.

For the purpose of app building, .h is the header file (the file that tells the app what to do), and .m is the implementation file (the file that does what the header told it to do).

Add the WebView to the Storyboard

The first step is adding the WebView to the Main.storyboard file. Upon selecting the file, you will be presented with a screen similar to below:

You will also be presented with an updated object list (located on the right hand side).

From this list find WebView and drag onto your Controller Canvas.

This will open up the View Controller Scene within XCode. From here, make sure View > Web View is selected.

This will allow you to tweak the settings for the WebView within your Mobile Application.

Make sure within your settings you have ‘Scale Page to Fit’ selected.

Update ViewController.m

Next step is updating ViewController.m. Select the file from the left hand side. From the code that loads up, paste the following under the value #import "ViewController.h".

@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
    webView.scalesPageToFit = YES;
    NSString *urlAddress = @"URL of a web page which has a UGC Widget";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    webView.contentMode = UIViewContentModeScaleAspectFit;
    webView.scalesPageToFit = YES;
    webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth);
    [self.view addSubview:webView];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

The section highlighted in yellow is where you will need to specify the URL to the page hosting your Widget.

Once done, save and build your Mobile Application.

Add WebView to your Android Mobile App

For the purpose of this guide, we will create a brand new Android Mobile Application on Android Tools.

From Android Tools, select New Project and fill out the following attributes:

  • Application Name: WebView Application

  • Target Android Devices: Phone & Tablet

  • Minimum SDK: API 15: Android 4.0.3 (IceCreamSandwich)

  • Mobile Activity: Blank Activity

  • Company Domain: Stackla

And select where you would like the application saved on your Computer.

Once setup you will notice on there left there will be a series of pre-generated files. The more important files to any Android App are:

  • src/main/java. Android Java source code.

  • src/main/res. Resources used by the native application.

  • src/main/res/drawable-type. Image resources used by the native application.

  • src/main/res/layout. XML layout files that define the structure of UI components.

  • src/main/res/values. Dimensions, strings, and other values that you might not want to hard-code in your application.

  • src/main/AndroidManifest.xml. The manifest file defines what's included in the application: activities, permissions, themes, and so on.

Add the WebView to the Main Activity Layout

Open the file res/layout/activity_main.xml and add the following code to the base of the document.

<WebView
        android:id="@+id/activity_main_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Update Main Activity Java Source Code:

Open the file java/stackla/webviewapplication/MainActivity.java and add the following highlighted code to the document.

package stackla.webviewapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.setInitialScale(1);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        mWebView.setScrollbarFadingEnabled(false);

        mWebView.loadUrl("URL to Widget Parent Page");
    }

    // ... rest of the code
}

This code ensures that the standard Android WebSettings and WebView kit are imported.

  • import android.webkit.WebSettings;

  • import android.webkit.WebView;

Whilst this code determines the rendering of the app within the Web View.

  • WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);

  • WebSettings webSettings = mWebView.getSettings();

  • webSettings.setJavaScriptEnabled(true);

  • mWebView.setInitialScale(1);

  • mWebView.getSettings().setJavaScriptEnabled(true);

  • mWebView.getSettings().setLoadWithOverviewMode(true);

  • mWebView.getSettings().setUseWideViewPort(true);

  • mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

  • mWebView.setScrollbarFadingEnabled(false);

This final line of code tells the Mobile Application what URL to load:

  • mWebView.loadUrl("URL to Widget Parent Page");

Update Android Manifest

Open the file /manifests/AndroidManifest.xml and add the following line of code right after the parameter <application>.

<uses-permission android:name="android.permission.INTERNET" />

Update Build Tool Version

If you see error "Cannot resolve symbol R", you might need to downgrade the build tool version.

Please open the file build.gradle and change buildToolsVersion to "21.0.1"

Once done, save and build your Mobile Application.

Best Practices for Web Apps

It is important to have a valid DOCTYPE and viewport in the parent page to prevent unexpected behaviours from different browsers. The article below listed some web apps best practices. Please ensure the web app follows the best practices at all times.

Summary and Next Steps

This example can be further expanded with the following activities:

  • Customise Widget to suit the look and feel of your current app

  • Integrate the above to switch Filters or Widgets within the Web Views

link
Best Practices for Web Apps