0

When using the following code on ionic 2 framework, everything works great on Android but when I converted it into iOS only the following bit of code doesn't work. I have been trying for past 2 days.

Please if someone can have a look and advise what's going on.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })
    export class HomePage {

      constructor(public navCtrl: NavController) {}

      proceedToPayment(){

        var mapForm = document.createElement("form");
        mapForm.target = "_blank";    
        mapForm.method = "POST";
        mapForm.action = "http://www.example.com/api/checkout.php";

        // Create an input
        var firstname = document.createElement("input");
        var lastname = document.createElement("input");

        firstname.type = "text"; firstname.name = "firstname"; firstname.value = "John";
        lastname.type = "text"; lastname.name = "lastname"; lastname.value = "Doe";

        // Add the input to the form
        mapForm.appendChild( firstname );
        mapForm.appendChild( lastname );

        document.body.appendChild(mapForm);
        mapForm.submit();

      }

    }
Devil Raily
  • 562
  • 1
  • 5
  • 15
  • iOS will prevent the consumption of insecure urls. You have to add a key-value to the `Info.plist`, check this answer -> http://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – dlcardozo Mar 15 '17 at 20:10
  • @camaron I have also tried this and it still doesn't work. – Devil Raily Mar 15 '17 at 21:32
  • change to https? .. i dont think iOS allows http anymore .. – Prashant Ghimire Mar 15 '17 at 22:04

1 Answers1

0

You need to have cordova-plugin-whitelist installed. If you don't have it yet, just run ionic plugin add cordova-plugin-whitelist.

Then add <allow-navigation href="http://*/*" /> to your config.xml

dlcardozo
  • 3,953
  • 1
  • 18
  • 22