S3GetObjectMetadataResponse Error, Crashes. How can I check it? - ios

I have an app that builds a dynamic list of files to be downloaded, using the Amazon S3 iOS SDK. No matter where in the queue I start the downloading from, the same file consistently crashes the application.
I've pinpointed the problem using breaks, and it's coming from my S3GetObjectMetadataResponse line as I attempt to get the size of the file before downloading, for the sake of configuring the progress bar.
self.S3 = [[AmazonS3Client alloc] initWithAccessKey:#"xxxxxxxxxxxxxxxxxxxx" withSecretKey:#"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"];
S3GetObjectMetadataRequest *getMetadataRequest = [[S3GetObjectMetadataRequest alloc] initWithKey:self.file.fileName withBucket:[self.file contentURLBucket]];
S3GetObjectMetadataResponse *metadataResponse = [self.S3 getObjectMetadata:getMetadataRequest];
If I comment out the last line, everything works as intended - except for the progress bar, of course.
What can I do to handle S3GetObjectMetadataResponse errors? Is there a better way I can check the file size before downloading?
Thanks!

As mentioned in my comment, you'll want to ensure that either exceptions are disabled in the AWS SDK for iOS or that you use a #try/#catch block in your code around synchronous calls when using the SDK.
This post on our blog explains how to disable exceptions and how to work with the SDK when exceptions are disabled.
This post is the first in a series that explains the various methods for using the SDK asynchronously. It is worth noting that if you make asynchronous requests with exceptions enabled you don't need the #try/#catch blocks.

Related

WKWebView loading local HTML require HTTPServer

I have website download to the iOS device locally run in WKWebView. I checked the website written to load JSON to construct the page. It requires an HTTP server support. I have a question that can WKWebView can support this scenario and how to code it? Many Thanks.
I have been facing a similar issue. UIWebView never had this problem, as it seemed to run a server in the background, so therefore constructing a page through json was never an issue. WKWebView, however, does not seem to be able to do this. One possible solution is to use a framework called Swifter that can be installed using CocoaPods. It basically emulates a server, so may make loading json in WKWebView a possibility.
https://github.com/httpswift/swifter
However, trying to use it myself, it seems to have problems with the latest Xcode 9 and Swift 4. If it gets sorted soon, it may solve your issue.

Omniture object "s" is not available immediately

I'm trying to track Page Load Event. I'm getting utag.js from Omniture.
I'm also wrapping it with jQuery: $.getScript to make sure that script is loaded.
But even then if I try to set my s.pageName or s.t(); I'm getting error that s is undefined. If I put a 500 ms timeout everything works fine. But I'm surprised that I need to wait even after script is loaded. Is it a common practice with Omniture?
I'm new to the Omniture, it might be very obvious thing for the more experienced users of Omniture.
utag.js is a Tealium loader, which I assume has Adobe Analytics code within it. The only thing that would prevent s from being defined after utag.js being loaded would be that the appmeasurement code is being loaded asynchronously.
You can find more about asynchronous loading here: https://tealium.com/blog/standard/asynchronous-tagging/
I would expect that once you switched to synchronous loading, the variables after utag.js will be able to reference the appmeasurement library.
App Measurement is not designed to be loaded asynchronously. I would suggest adding a "flag" that will indicate when utag.js has loaded and then reference the s.object.

Is window.requestFileSystem method is deprecated?

I am currently working on an old iOS app. I don't have much idea about cordova.
I am stuck at one place, where code uses window.requestFileSytem . There is some code in success callback of this function.
When I debug, I found that success callback is not triggered. I am not able to find any thing about this function in latest cordova document however there is some thing in older document.
So I am worrying about is window. requestFilesystem method is deprecated. If so then how can I achieve same thing in latest cordova.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onReqFileSystemSuccess, null);
Any help would be appreciated.
Reviewing #iammilinds answer I have to correct my initial statement:
The window.requestFileSystem method is non-standard and should not be used. See the linked MDN docs.
Yet there are code examples containing the window.requestFileSystem method in the documentation for the cordova file plugin here or here (searching for window.requestFileSystem might help as the dcos are pretty large).
So regarding your initial problem: I'm afraid you'll have to debug it. Maybe checking the browser's console might give you a hint what's wrong. Or try to add an error handler to window.requestFileSystem as the last parameter like so:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onReqFileSystemSuccess, onErrorLoadFs);
Yes, it's deprecated.
It's implemented only by Chrome as of today.
This is what Mozilla page for Window.requestFileSystem() for this API says:
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
Above notice can be seen for several other "Files & Directories" APIs. However, below notice is significant and is read only for this particular API.
Even compared to the rest of the File and Directory Entries API, requestFileSystem() is especially non-standard; only Chrome implements it, and all other browser makers have decided that they will not implement it. It has even been removed from the proposed specification. Do not use this method!
The correct usage is as discussed in this post: How to use window.requestFileSystem of FileSystem API?
window.requestFileSystem = window.requestFileSystem || // Chrome
window.webkitRequestFileSystem; // Others

XCUIApplication replacements for UIATarget captureScreenWithName()

We are trying to migrate from UIAutomation to XCUITests and did use the captureScreenWithName() API to programmatically generate screen shots.
What is the replacement in the XCUITests ?
(I know that automatically screenshots are taken in case of error, but we have a special test which runs forever in a loop and evaluates QA click,tap commands via network similar to the appium-xcuitest-driver https://github.com/appium/appium-xcuitest-driver)
Do I need to rip out private headers (XCAXClient_iOS.h) like the appium guys did in order to get a screenshot API?
Edit
I used the actual code line for the accepted solution from
https://github.com/fastlane/fastlane/blob/master/snapshot/lib/assets/SnapshotHelper.swift and its just this for IOS
XCUIDevice.sharedDevice().orientation = .Unknown
or in objC
[XCUIDevice sharedDevice].orientation =UIInterfaceOrientationUnknown;
I use a process on the host to lookup in the "Logs/Test/Attachments" directory all Screenshot_*.png files before the call , and find the new shot then after the call as the new file added in this directory.
Gestures (taps, swipes, scrolls...) cause screenshots, and screenshots are also often taken while locating elements or during assessing expectations.
Fastlane's snapshot tool uses a rotation to an unknown orientation to trigger a screenshot event (which has no effect on the app): https://github.com/fastlane/fastlane/tree/master/snapshot - you can use this if you want to be in control of some screenshots.

How can stdout be redirected in iOS?

I am importing some legacy code into an iOS app that uses stdout for some diagnostic output. Of course, iOS does not like you to write to stdout at all, and I need to get that output anyway. I would like to redirect this output to a file, then use the same legacy code again, redirecting the output to a different file. Does anyone know of a way to do this?
I've tried the simplistic
freopen(p, "w", stderr);
This does work--but only once. After using this call, all output to stdout is forever redirected. That's OK, but subsequent calls to redirect the output to a new location cause system instability that eventually leads to a crash. (I have tested this running from XCode, but not directly from a rebooted iPad. I don't know for sure the instability persists if not running in XCode using DEBUG mode.)
I've also tried the method in this post. This works, too, but does not return the system to its original state, and again, only works once. (If you try this at home, include Apple's <unisys.h> instead of <io.h>, and leave the _ off of calls like _dup and _dup2.)
I really don't want to have to go through the code and replace all uses of printf, etc to use an explicit file. In addition to being time consuming, error prone, and ugly, the code is open source. I don't expect the original authors would appreciate my changes, and I don't really want to have to reintegrate the changes each time the original project is updated.
Thoughts?

Resources