Wednesday, November 16, 2011

Phonegap | Whitelist rejection in phonegap compilation with Xcode

While having an other domain server based service. Our phonegap application failed with ERROR logs :
whitelist rejection in phonegap compilation
The solution is to Whitelist (allow) the host to be accessible via phonegap, to accomplish it
In Phonegap.plist file,
Add new row to External Host (Key value pair)
for value, put your host name : (SERVER.COM).
e.g.
1) ERROR whitelist rejection: url('http://localhost:XXXX/myproject/index')
Type: localhost in value column for for External Host
2) ERROR whitelist rejection: url('http://myserver.com/dashboard/mobilews.php?')
Type: myserver in value column for External Host


May be putting "*" , the asterisk as a value of the host that references an external URL , will do the trick. but not safe.
hope this helps, It works great for us :)

see my comments below for more info, as phonegap is cordova now!

16 comments:

  1. Thanks! :) it worked perfetly after adding .com and a star prior the hostname.

    ReplyDelete
  2. I have tried all the difference versions of External hosts but still do NOT get around this Whitelist rejection. (ERROR whitelist rejection: )
    Are there any unknown issues in XCode 3.2.6 and PhoneGap 1.4.1 that explains this.
    Tried *.*, *[domainname].*, *, *.[domainname].com
    The simulator (iOS4.3) can connect to the internet.. it is just my app that cannot.
    Doing a basic Jquery Ajax call.

    ReplyDelete
  3. hmm, just try to put SERVER_HOST_NAME of which server host you are trying to connect. e.g. "google" for http://google.com

    If you still have trouble:
    Better will be to send the code to me, so that I can look into.

    Feel free to reach me via Skype "garg.praveen" or email "er.praveengarg@gmail.com".

    --Best
    Praveen

    ReplyDelete
  4. I found the problem. In the Xcode editor it is easy to add the ExternalHosts as an extra row, and not as a subset of the External Hosts node...
    I should have edited the file with a text editor rather.

    ReplyDelete
  5. btw, if we need to allow multiple hosts to be connected And we want to add only specific host names (NOT any of the external hosts i.e. *) THEN we should add them as a subset of the External Hosts node.

    Hope! It make sense.

    ReplyDelete
  6. Phonegap is actually the part of Apache foundation now, and they named it as Cordova (intially apache callback). so there shall be a Cordova.plist now. and we need to make changes in that plist.

    As per the documentation.
    The latest (Cordova) code has the new white-list feature. If you are referencing external hosts, you will have to add the host in Cordova.plist under the "ExternalHosts" key. Wildcards are okay. So if you are connecting to "http://'www.mydomain.com", you have to
    add "mydomain.com" to the list (or use the wildcard "*.mydomain.com" which will match subdomains as well).

    ReplyDelete
  7. Hello Sir, Really your blog shorted out my problem. Since the very beginning day I was facing this error in Cordova framework. Thanks a lot!!!

    ReplyDelete
  8. thanks a lot for this blog. thanks a ton..dinesh

    ReplyDelete
  9. Got a question, I'm running Xcode 4.3.2 now with 1.7.0 PhoneGap. I've tried all versions of this and still it isn't working, due to the upgraded versions (started at this version) is there a different way of going about this? Also, when adding a new value does the Type need to be "String"?

    Thanks,

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. @Billy,

    Can you please send that plist via email/dropbox? My email id is (er.praveengarg@gmail.com)
    Yes, you need to Add host value as a String node (chile node) of ExternalHost (parent node of type array)...

    ReplyDelete
  12. Good work, extremely helpful!

    ReplyDelete
  13. Thanks ! That helped !

    ReplyDelete
  14. Hi nice to meet you Praveen.I still cant fix it.let say my url is not start with "www" .eg:"http://abc.abc.com" what shall i put i the value string.i try add *abc.abc.com/abc.abc.com/abc.com still dint work. please help me out of this.
    thank you

    ReplyDelete
    Replies
    1. Try
      FIRST:
      *.abc.com Here abc is main domain name.

      SECOND:
      *.* (in case, you see some challenge in FIRST case)
      Hope this will solve your issue.
      --Best
      Praveen

      Delete