I have a file handle set up to read the contents of stdout, and when I try to pull the data out of it using availableData it hangs, but only when the app is run manually on my device. When I run the app on my device through Xcode or on the simulator, it pulls the data out as expected and the rest of my code works perfectly. Any ideas what is happening? My code is below:
int pipefd[2];
pipe(pipefd);
dup2(pipefd[1], STDOUT_FILENO);
close(pipefd[1]);
NSFileHandle *stdoutReader = [[NSFileHandle alloc] initWithFileDescriptor:pipefd[0]];
// this method writes output to stout
int result = [self createOutput:string1:string2];
// code hangs on this next line when app is run manually on device)
NSData *stdoutData = [stdoutReader availableData];
I am wondering if on my device, the createOutput method runs more slowly and so by the time I try to get data out of stdout there isn't any yet?
Well, it looks like iOS 5.1 doesn't allow writing to stdout anymore. For anyone interested in reading more, here's an informative blog post: http://spouliot.wordpress.com/2012/03/13/ios-5-1-vs-stdout/
Related
I want to read inputs from debug console, to create commands that will be read by the app in order to get more control in my app. For example I want to send commands like:
addCoins 200
and my app should read this line and parse it to call the function:
addCoins(amount: 200)
In the didViewLoad I tried to create an async function and inside read console to know if the user has written some commands but it is not working.
I am not sure if it is possible at all.
My code inside the viewDidLoad is:
let queue = DispatchQueue.global()
queue.async {
let command = readLine(strippingNewline: true)
if command != nil {
//parse command to do something
print("\(command)!")
}
}
I want to read the commands as following:
Your application can not read your console input if it's an iOS app. You can certainly use debugging features to read information during runtime.
You might not need this but, in the lldb debugger, you can set up breakpoints and use basic commands to read and modify some information at runtime. Apple has a comprehensive tutorial on Xcode debugging. Debugger You can also look at lldb tutorial here. lldb tutorial
I'm testing the framework HockeyApps for testing apps with iOS, it seems I added successfully my app.
I added a code which is triggered after the user touches a button, the code is very simple:
- (IBAction)didClickAuthenticateOptions:(id)sender {
NSString *s = #"x";
id obj = s;
NSArray *arr = obj;
NSLog(#"the array has the following lenght:");
NSLog(#"%lu", (unsigned long)[arr count]);
}
this code will terminate with a crash on my app.
I installed and executed my app normally on my iPhone, and the crash report was sent to my site:
but when I opened the crash report, I expected to get information about the file, method, line of code that provoked the crash
when I clicked on "view raw log" I got all this:
raw log
How to find the method, line and code that provoked the crash in all that log???
thanks in advance for the support
This is because you did not yet upload the correct dSYM files to HockeyApp. They are needed to translate the cryptic memory addresses back to readable filenames, method names, and line numbers.
There some more info on how to find the correct dSYM here.
I'm building a cordova app (primarily for IOS & Android) in which the user can take an image, retake (, etc.) it and save it locally.
I'm currently struggling with the cordova cameraPlugin. So, here a short description of the problem.
When the user takes an image, it's saved locally in the apps temp folder and the user is able to view in in the UIWebView. On retaking, the image will be deleted from the temp folder and should not be available any longer (in RAM and local FS).
It works as long as the user doesn't retakes the image 2 or more times, if he does instead of the last image the first image will be referenced/rendered in WebView. After reopening the app, the image is displayed correctly.
An Example:
The user takes the first image. ==> cdv_photo_001.png
The second. ==> cdv_photo_002.png and the first one will be deleted (which seems to work correctly)
And the third. ==> cdv_photo_001.png and the second image will be deleted.
The third image will look the same as the deleted first one. This happens with every image after the third one.
It works fine after restarting the app
I've already tried to disable the App-Cache, delete the app cache before updating the image, refreshing the page and looking for answers online.
I'm getting an error when opening the camera UI, but I could not find a solution for it either.
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before
snapshotting or snapshot after screen updates.
The code for the camera Call:
function getPhoto() {
navigator.camera.getPicture(getPhotoOnSuccess, getPhotoOnFail, {
quality: 25,
destinationType: Camera.DestinationType.FILE_URL,
correctOrientation: true,
encodingType: Camera.EncodingType.PNG
});
}
In getPhotoOnSuccess I'm basically saving the image path to a db and appending it with jQuery to the view.
And the code to delete the image: (sidenote I`m new to Objective C)
- (void) deleteImageByPath:(NSString *)imagePath withSelector:(SEL)selector{
NSError *error = nil;
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *tempFolder = NSTemporaryDirectory();
if([mgr removeItemAtPath: imagePath error:&error] == NO) {
NSLog(#"File deleted");
}
//The files can be edited as well, so there can be two files in different directories
if(error != nil){
NSString *imgEl = tempFolder;
imgEl = [imgEl stringByAppendingPathComponent:imagePath.lastPathComponent];
if(![mgr removeItemAtPath:imgEl error:&error]){
NSLog(#"Old element couln't be deleted.");
}
}
[self performSelector:selector withObject:error];
}
The file is not in the directory anymore after deleting it, so I guess it works.
An important detail could be, that I wrote my own IOS cordova plugin, because the method for the file system access provided by cordova sucks.
So thats it.
The specific question is: Why and how is this happening and is there a chance to change this behavior? If yes, how should I proceed?
By the way, I`m using cordova 3.1.0 and the build target is IOS 7.
Thanks in advance.
Ok folks, I finally got it.
The whole problem was not related to my code or any of the cordova code.
So why did it happen? ==> I don't exactly know that, for it seems that this bug or whatever you might call it, has occurred to many people.
And they all tried to delete or deactivate the cache as I did, some of their problems are very close to my own but most aren't, so it took a while til I found a solution.
I read this thread and tried to append a timestamp to the image path and it worked!
My conclusion to this it, that there might be a problem with the UIWebView and the cache management.
Or it might proof as a general WebView problem, I will be able to check that in a few days on an Adroid device.
I am banging my head about an issue I have on iOS7 development. I use the following piece of code to load an image from a webserver:
NSData* data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://someServer/someImage.jpg"]];
This works like a charme in simulator, reading exactly the 134185 bytes that the image has. Creating an UIImage from that data works as intended.
Once I test the exact same code on a device (iPad Mini, iOS 7.03), though, it just reads 14920 byte from the same URL. Needless to say that I can't create an UIImage from that data then, creation fails and returns a nil.
The read does not produce any errors (no console output, and also using the signature with the error output param returns nil here). Is there anything I missed around this rather straightforward task? Haven't found anything on the web on this…
Thanks, habitoti
So you don't have any error, and something is downloading. Maybe try to read this response and post here (I guess it is html/text body)?
You can use NSString method:
+ (instancetype)stringWithContentsOfURL:(NSURL )url encoding:(NSStringEncoding)enc error:(NSError *)error;
Can I suggest you use a library like SDWebImage to retrieve your image, it caches it and downloads the images asynchronously.
It also has a category for UIImageView so you can just call [imageView setImageWithURL:]; and it will load the image in when its ready.
I have an app that runs a synchronization algorithm.
When I build and run it in debug mode (onto my iPhone 5) it all works fine.
However, when I archive it and upload it to TestFlight and then download and install to the same iPhone 5 then part of the sync doesn't work.
It doesn't crash or anything, it just doesn't run that part of the sync.
The stupid thing is that it is a line of code inside a single function that isn't running. Everything else in that function does run.
I have no idea where to start looking for this.
EDIT
With help from Mindaugas I've found exactly why and which bit of code is not being run.
The function is...
- (void)uploadData
{
NSLog(#"pushing photos");
for (StoredImage *storedImage in self.recordArray) {
NSURL *url = [self urlForImageUpload:storedImage];
if (url == nil) {
continue;
}
ImageUploadOperation *uploader = [[OJFImageUploadOperation alloc] init];
uploader.image = storedImage.image;
uploader.url = url;
[self.recordQueue addOperation:uploader];
}
}
When I set the optimisation level to "Fastest, Smallest" it seems to mess the order of this function up.
When it enters I can see that there is a single object in the array and it enters into the loop. But then it completely skips past the first line NSURL *url = [self urlForImageUpload:storedImage]; and goes to the end. So the upload never actually starts and it moves onto the next item.
Release configuration by default uses different code optimization than Debug configuration, so some code lines can be optimized and skipped
You can check/change configurations at
Target -> Build Settings -> search for Optimization Level