Xcode save html from server to plist - html

I have on my server a php code, when its called mydomain.com/index.php?id=11, it creates PList-format. But I must save this first on my computer via Browser(safari->save page) and must change the suffix from (.html) into (.plist), so all steps are manually. And then it used in Xcode.
How I can download direct this code by calling mydomain.com/index.php?id=11 in Xcode and save as .plist ??
Thank You!

Assuming the Plist contains an array of objects, are you able to do this?
NSURL *myURL = [NSURL URLWithString:#"http://mydomain.com/index.php?id=11"];
NSArray *myArray = [NSArray arrayWithContentsOfURL:myURL];
//either use the array as it is or save it to file:
NSString *myPath = #"some/path.plist";
[myArray writeToFile:myPath atomically:NO];
The same approach would work for a dictionary. I don't think that the suffix matters when doing this, but I haven't tried it myself.

Related

Accessing filesystem in Angular 5, using electron

I'm building an simple stand-alone angular application in which u can submit information.
This information needs to be saved in a local JSON file that's in the asset folder. I know Angular runs in a web browser that's why I use electron to build it. The problem is that i can't figure out a way to edit the JSON files in angular 5 using electron (local).
I have tried the solutions mentioned in this post, But they didn't work for me, any other solutions?
After having this problem for quite some time i finally figured out how to solve it:
you need to put this in script tags in your index.html
var remote = require('electron').remote
var fs = remote.require('fs');
and in every component you want to use it you need to declare it globally
declare var fs: any;
then you can use it!
was quite a struggel to figure it out...
Because it's just JSON data, might I suggest using localStorage instead? Then, you can do something like:
...// Code that creates the JSON object
var theJSONdata = jsonObj.stringify(); // conver the object to a string
window.localStorage.setItem('mysavedJSON', theJSONdata)
;
Later, when you need to load the JSON to edit it or read it, just use:
jsonObj = JSON.parse(window.localStorage.getItem('mysavedJSON');

How to embed html in Xcode Project for iOs8

I have been developing an iOS application - a really simple application that is based on HTML and CSS (some of them will be using PHP and my SQL) However, I have been trying to find the way to embed HTML file in my project but all the tutorials that I had found (so far) would be either for older version or there is something missing in my Xcode (like file's owner button) which doesn't make it easy or sometimes in the tutorial that I followed had something different from my current version of Xcode. (I am really new to Xcode) my Xcode version is 6.1 running on the latest version of OSx Yosemite. I might have missed something that I should know about embedding HTML file in Xcode 6 for iOS8? I would be appreciated for any answer. Thank you.
I have tried to do the same a month ago, displaying html in iOS8. My html didn't need CSS though. But I suppose the way to do it is not so different.
We can load the html file as string and that display it with an UIWebView as follows:
var filePath = NSBundle.mainBundle().pathForResource("HtmlFileName", ofType: "html")
var htmlString = NSString.stringWithContentsOfFile(filePath!, encoding: NSUTF8StringEncoding, error: nil)
var myWebView = UIWebView(frame: DeviceUtil.getScreenRect())
myWebView.loadHTMLString(htmlString, baseURL: nil)
var viewController = UIViewController()
viewController.view = myWebView
self.navigationController?.pushViewController(viewController, animated: true)

How to load an image using its real path in Grails

My idea is to save the images which the user uploads outside the context path as follow:
D:\somefolder\myWeb\web-app\
D:\somefolder\imagesOutsideContextPath\
The code for that is the next (working locally):
String path = servletContext.getRealPath("/");
String parentFolder = new File(path).getParentFile().getParent();
String imagesFolder = parentFolder + "\\imagesOutsideContextPath";
Another idea (if this one doesn't work on server) would be to save the images in the current user's home folder as #HoàngLong suggested me.
But I'm not able to load the images from the view. I think this article from official documentation is not valid for that purpose. The next code desn't load anything:
<img src="D:\\somefolder\\imagesOutsideContextPath\\bestImageEver.jpg" alt="if I don't see this message, I'll be happier">
How could I use the real path instead the an url path to load these images?
There's a new plugin that makes this easy, check out http://grails.org/plugin/img-indirect
Create an action
def profileImage() {
String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${params.id}"
File file = new File(profilePicturePath)
response.contentType = URLConnection.guessContentTypeFromName(file.getName())
response.outputStream << file.bytes
response.outputStream.flush()
}
and then call this action with image name in params like:
<g:img uri="${grailsApplication.config.grails.serverURL}/controller/profileImage/${user?.profilePicture?.fileName}"/>
I have declared the image directory file in my config.groovy file like:
profilePictureDirectoryPath = '/opt/CvSurgeon/profileImages'
You can set the src to an action. With that your user will not know where your images are stored (security) and you can easily change your logic to display them.
In the action, just get your image and print the bytes. Example here.
Firstly, thank you for your reference.
It's insecure to load images using real path. The web browser should know nothing about how the pictures are saved on server, therefore not aware of the folder structure.
What I mean is that the system should use a specific URL for all your pictures, such as http://your_app/photo/user/{id}. Then to that URL, you can construct an action which gets id as a parameter, look up the photo in your file system(of course you must store the picture folder in configuration), and render the photo back.

Can I store application cache of HTML5 when packaging my hybrid app?

I am developing an hybrid app.
It will bring contents from my server, and I will use application cache for performance and traffic cost issues.
Even though I use application cache, the users would have to download webpages whenever they open the pages first time.
I want to store the application cache before upload the app onto google play and apple app store.
Then, the app will only check manifest file if the page is not updated after packaging.
Can I store the application cache in the hybrid app? If then, where can I get the how-to documents, or how can I do that?
Thank you in advance!
p.s:I will package the webapp with phonegap.
Better to answer late than never, I guess!
The answer is yes, it is possible. I've got two apps in the app store that are doing this. It works reasonable well, although it's a painful process (mainly because appcache is a douche)and we're using a customised version of Cordova in order to do it.
Here's a rough idea of how you can implement this:
Have an empty local stub index.html that your Cordova startPage points at.
Implement webViewDidFinishLoad in your webview. It will do two things - open the appcache page on start and inject your cordova.ios.js into the subsequent pages. Something like this:
- (void)webViewDidFinishLoad:(UIWebView*)webView {
if(!_initialPageLoaded) {
_initialPageLoaded = YES;
NSURL *url = [NSURL URLWithString: #"https://mywebsite.com/app/"];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:ful];
[self.webView loadRequest:req];
return;
}
NSString* jsPath = [[NSBundle mainBundle] pathForResource:#"www/cordova.ios" ofType:#"js"];
NSString* c = [NSString stringWithContentsOfFile:jsPath encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:c];
return [super webViewDidFinishLoad:webView];
}
Profit!
Note that the cordova.ios.js file is local to the application, so don't keep it on your webserver.

How to put\save files into your application directory? (adobe air)

How to put\save files into your application directory? (adobe air) (code example, please)
It's not recomended but it is possible. Construct your File reference like this:
var pathToFile:String = File.applicationDirectory.resolvePath('file.txt').nativePath;
var someFile:File = new File(pathToFile);
You can't write to your AIR app's Application Directory, it's not allowed. You can however write to a folder that your AIR app creates in the user's directory, called the Application Storage Directory. If you need config files and the like, that's probably the best place to put them. See 'applicationDirectory' in the docs link below:
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/
#glendon
if you try to save directly to applicationDirectory it will indeed throw an error, but it seems you can move the file in the filesystem. i used the code below after yours:
var sourceFile:File = File.applicationStorageDirectory.resolvePath ("file.txt");
var pathToFile:String = File.applicationDirectory.resolvePath ('file.txt').nativePath;
var destination:File = new File (pathToFile);
sourceFile.moveTo (destination, true);
the reason why you 'shouldnt' use the application folder is because not all users have rights to save files in such folder, while everyone will in applicationStorageDirectory.
The accepted answer works!
But if I do this instead:
var vFile = File.applicationDirectory.resolvePath('file.txt');
var vStream = new FileStream();
vStream.open(vFile, FileMode.WRITE);
vStream.writeUTFBytes("Hello World");
vStream.close();
It will give SecurityError: fileWriteResource. However, if I use applicationStorageDirectory instead, the above code will work. It'll only NOT work if it's applicationDirectory. Moreover, Adobe's documentation also says that an AIR app cannot write to its applicationDirectory.
Now, I wonder if it's a bug on Adobe's part that they allow writing to the applicationDirectory using the way suggested by the accepted answer.
try this.
var objFile:File = new File(“file:///”+File.applicationDirectory.resolvePath(strFilePath).nativePath);
the output would be like this…
file:///c:\del\userConf.xml
This will work fine.
If you want write file into ApplicationDirectory, right?
Please don't forget for write for nativeprocess via powershell with registry key for your currect adobe application ( example: C:\Program Files (x86)\AirApp\AirApp.exe with RunAsAdmin )
nativeprocess saves new registry file
AirApp will restarts into RunASAdmin
AirApp can be writable possible with file :)
Don't worry!
I know that trick like sometimes application write frist via registry file and calls powershell by writing nativeprocess into registry file into registry structures.
Look like my suggestion from adobe system boards / forum was better than access problem with writing stream with file :)
I hope you because you know my nice trick with nativeprocess via powershell + regedit /s \AirApp.reg
and AirApp changes into administratived AirApp than it works fine with Administratived mode :)
Than your solution should write and you try - Make sure for your writing process by AirApp.
this function gives your current air application folder which bypasses the security problem:
function SWFName(): String {
var swfName: String;
var mySWF = new File(this.loaderInfo.url).nativePath;
swfName= this.loaderInfo.loaderURL;
swfName = swfName.slice(swfName.lastIndexOf("/") + 1); // Extract the filename from the url
swfName = new URLVariables("path=" + swfName).path; // this is a hack to decode URL-encoded values
mySWF = mySWF.replace(swfName, "");
return mySWF;
}