Talk:IOS

From BC$ MobileTV Wiki
Jump to: navigation, search

iOS for Android developers

Android iOS
AndroidManifest.xml Info.plist (also an XML file)
var (dynamically-typed variable) var (mutable variable)
int x = 2; or String y = "abc"; typed variable var x = 2 or var y = "abc"
protected|private static final Object|String|int|... (constant) let (immutable variable)
@Override override
onCreate viewDidLoad
onStart sceneDidBecomeActive
onPause sceneWillResignActive
onResume sceneWillEnterForeground
??? didReceiveMemoryWarning
onStop sceneDidEnterBackground
onDestroy applicationWillTerminate
Activity Storyboard
ViewModel lib SwiftUI
Intent Segue
ActionBar NavigationBar
BottomNavigationView ToolBar
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);

Editor editor = sharedpreferences.edit();
editor.putString("yourVariable", yourVariable);
editor.commit();

NSUserDefaults.standardUserDefaults().setObject(yourVariable, forKey: "yourVariable");
Inside of onCreate() or corresponding Listener where the call will be initiated:
 FetchData asyncTask = new FetchData();
 asyncTask.execute("https://www.example.com/data");

Inline, Anonymous, or separate class imported in the Activity where it will be called:

 private class AsyncTaskExample extends AsyncTask<String, String, InputStream> {
     @Override
     protected void onPreExecute() {
        super.onPreExecute();
     }
     @Override
     protected InputStream doInBackground(String... params) {
       InputStream data;
       HttpURLConnection conn;
       try {
           URL url = new URL(params[0]);
           conn = (HttpURLConnection) URL.openConnection();
           conn.setDoInput(true);
           conn.setReadTimeout(10000 /* milliseconds */);
           connection.setConnectTimeout(15000 /* milliseconds */);
           connection.setRequestMethod("GET");
           connection.setDoInput(true);
           conn.connect();
           data = conn.getInputStream();
        } catch (IOException e) {
           e.printStackTrace();
        } finally {
           conn.close();
        }
        return data;
     }
     @Override
     protected void onPostExecute(String response) {
        super.onPostExecute(response);
        //do something else with "response" like parse (XML, JSON, etc), display the remote image, stream the remote audio/video file, etc...
     }
 }
From within viewDidLoad() or corresponding Listener where the call should be triggered:
 let url = NSURL(string: "https://www.example.com/data")
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
if (let response = data { let content = NSString(data: response, encoding: NSUTF8StringEncoding) dispatch_async(dispatch_get_main_queue(), { () -> Void in self.webView.loadHTMLString(String(content), baseURL: nil) }) } else { //show error message }

} task.resume()

Google Play store, Samsung app, Amazon Fire app store, BlackBerry app store Apple iTunes, Apple App Store

External Links