Error on fromNSString function in Codename one

54 views
Skip to first unread message

mispro...@gmail.com

unread,
Aug 26, 2016, 7:21:02 AM8/26/16
to CodenameOne Discussions
Dear Sir,

Please refer to the error shown below


Please suggest any solution for the error above. We are logged and sure there is a string value passed before that function be called.

Thanks and Regards,
Ronald
Auto Generated Inline Image 1

Shai Almog

unread,
Aug 27, 2016, 1:53:34 AM8/27/16
to CodenameOne Discussions, mispro...@gmail.com
The error isn't here. It's before this point as str is corrupted by the time you reached this code.

mispro...@gmail.com

unread,
Aug 28, 2016, 11:11:48 PM8/28/16
to CodenameOne Discussions, mispro...@gmail.com
Hi,


-(NSString *)restorePhoto:(NSString *)param param1:(NSString *)param1 param2:(NSString *)param2{
__block BOOL bResult = NO;
__block NSString *sFilePath = @"";
NSString *sAppDocPath = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] path];
sAppDocPath = [sAppDocPath stringByAppendingPathComponent: @"cn1storage"];
NSString *sTmpFilePath = [sAppDocPath stringByAppendingPathComponent: param];
NSData *data = [[NSFileManager defaultManager] contentsAtPath: sTmpFilePath];
__block NSConditionLock * albumReadLock = [[[NSConditionLock alloc] initWithCondition:WDASSETURL_PENDINGREADS] retain];

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[assetsLibrary saveImageData: data
toAlbum: param2
metadata: nil
completion: ^(NSURL *assetURL, NSError *error) {
if (error) {
bResult = NO;
} else {
bResult = YES;
//sFilePath = [NSString stringWithString:[assetURL absoluteString]];
//sFilePath = [[assetURL absoluteString] copy];
sFilePath = [[NSString alloc] initWithString:[assetURL absoluteString]];
}

[albumReadLock lock];
[albumReadLock unlockWithCondition:WDASSETURL_ALLFINISHED];
}
failure: ^(NSError *error) {
NSLog(@"[restorePhoto] There is an error: %@", error);
[albumReadLock lock];
[albumReadLock unlockWithCondition:WDASSETURL_ALLFINISHED];
}
];

/*
[assetsLibrary writeImageDataToSavedPhotosAlbum:data metadata:nil
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
bResult = NO;
} else {
bResult = YES;
}

[albumReadLock lock];
[albumReadLock unlockWithCondition:WDASSETURL_ALLFINISHED];
}
];

*/
});

[albumReadLock lockWhenCondition:WDASSETURL_ALLFINISHED];
[albumReadLock unlock];

[albumReadLock release];
[assetsLibrary release];

//[sFilePath autorelease];
NSLog(sFilePath);
return sFilePath;
}


It is the native function we called then the string return. We can sure the "sFilePath" value is exist before return. Then it goes cn1 library code till the error as previous post.
For your reference, the three strings params
1. param : tmp{datetime}_{filename e.g. IMG_123.JPG}
2. param1 : {filename}
3. param2 : "Camera Roll"


Please help to find out the solution. I would appreciated if the problem could be solved in a few days.

Thanks and Regards,

Shai Almog

unread,
Aug 29, 2016, 1:25:16 AM8/29/16
to CodenameOne Discussions, mispro...@gmail.com
Hi,
try [sFilePath retain];

mispro...@gmail.com

unread,
Aug 29, 2016, 2:00:04 AM8/29/16
to CodenameOne Discussions, mispro...@gmail.com
It is tried but the problem retain.

Thanks,

On Monday, August 29, 2016 at 1:25:16 PM UTC+8, Shai Almog wrote:
Hi,
try [sFilePath retain];

Steve Hannah

unread,
Aug 29, 2016, 10:33:22 AM8/29/16
to codenameone...@googlegroups.com
Your native function doesn't do what you think it does.  You are returning sFilePath from your function, but its value is being changed inside of your dispatch_async call - which happens after you've already returned from your function. 

Since your function uses async callbacks internally to set the sFilePath, you'll need to change your native function to by asynchronous also, and use a callback to pass the string back to your app.

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/ba08dbf5-f6ae-469c-96c6-3e2ea3ec3c74%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

mispro...@gmail.com

unread,
Aug 29, 2016, 9:33:03 PM8/29/16
to CodenameOne Discussions
Hi Steve,

Thanks for your advice, let we try!
Reply all
Reply to author
Forward
0 new messages