0

I am aware that it isn't possible to download and execute objective-c / swift code from server on device without getting rejected. However, is it possible to download let's say some javascript or some other language code and execute it on device?

I am building an app where I need to evaluate whether a user's String passes through validation through various operations.

For example user has a string ABC123.

My list of operations (which will be dynamic, so I can add more operations from server side) can be:

  1. Is String.length == 6?
  2. Is String.substring (3,5) numeric?
  3. Is sum of digits at 4,5,6 positions == 6?

etc.

I was thinking of downloading some JavaScript code from my server which had the entire list of operations. Then passing the user string through this code for validation. However I am not sure how to do this.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Any reason to no execute your operations on server side and return a result to your client ? – GIJOW May 22 '17 at 20:38
  • 1
    @GIJOW Yes, mostly because it will reduce the load on my server. I am using a free version of server which limits the number of requests and response I can send. If I can do the operations on the client side, my server won't have to do the calculations. – sudoExclaimationExclaimation May 22 '17 at 21:14
  • Yes, in this case you can use Owen suggestion. Get your script into a webview and in your swift you can call those scripts and get its results. There some ways to use "embedded" js in swift, one of them is to use the class WKUserScript from webkit or stringByEvaluatingJavaScript from your webview. – GIJOW May 22 '17 at 21:21
  • maybe it can be helpful https://stackoverflow.com/questions/35650931/get-javascript-function-response-in-ios-using-swift – GIJOW May 22 '17 at 21:23
  • @GIJOW do you happen to know if Apple will reject my app for this kind of code download / execution? I am using it for legitimate purposes. – sudoExclaimationExclaimation May 22 '17 at 22:05
  • I'm almost sure you'll not have any problem. I would implement in webpages and get execution from webview inside your app. You can implement in a such way that the user will not realize they are in a webpage – GIJOW May 23 '17 at 02:42
  • @GIJOW Ok thank you! I will update with solution once I try it. – sudoExclaimationExclaimation May 23 '17 at 04:22

1 Answers1

0

You can open any webpage in Safari, or in a UI/WK WebView, and run javascript on those pages. Certainly, you can run these tests in Objective C without going to the server, or you can setup some RESTful calls using something like AFNetworking to send your string to your server, and have it return the appropriate result.

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35