Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve value from NSDictionary type #817

Closed
jibon57 opened this issue Nov 3, 2017 · 9 comments
Closed

Retrieve value from NSDictionary type #817

jibon57 opened this issue Nov 3, 2017 · 9 comments

Comments

@jibon57
Copy link

jibon57 commented Nov 3, 2017

Hello

I am trying to implement one Native library in NativeScript (https://github.com/hackiftekhar/IQMediaPickerController#example-usage). The native code like this:

@implementation ViewController
{
    NSDictionary *mediaInfo;
}

- (void)mediaPickerController:(IQMediaPickerController*)controller didFinishMediaWithInfo:(NSDictionary *)info;
{
    NSLog(@"Info: %@",info);//Here you'll get the information about captured or picked assets

    mediaInfo = [info copy];
    [self.tableView reloadData];
}

So, I am trying like this:

public mediaPickerControllerDidFinishMediaWithInfo(controller, info) {
   let mediaInfo = info.copy();
   console.log(mediaInfo);
}

I am getting output like this:

{
    IQMediaTypeImage =     (
                {
            IQMediaImage = "<UIImage: 0x608000290090> size {4288, 2848} orientation 0 scale 1.000000";
        }
    );

But I can’t acccess the information. Thanks in advance.

@tdermendjiev
Copy link
Contributor

Hi @jibon57, if I understand correctly you are getting the proper NSDictionary by the delegate method but don't know how to access its values. According to Apple docs you can do it by calling dictionary.objectForKey(key). I had a look at the library's repository and it seems like they are using the same pattern as in UIImagePickerControllerDelegate, i.e. accessing media info values by using constants such as UIImagePickerControllerOriginalImage. That said, you should be able to access the image by calling mediaInfo.objectForKey(IQMediaTypeImage).

@jibon57
Copy link
Author

jibon57 commented Nov 26, 2017

@tdermendjiev Thanks for your reply & sorry for late response. I just tried as your suggestion like this:

public mediaPickerControllerDidFinishMediaWithInfo(controller, info){
            let mediaInfo = info.copy();
            let data = mediaInfo.objectForKey("IQMediaTypeImage")
            console.log(data);
        }

Output:

CONSOLE LOG file:///app/tns_modules/nativescript-filepicker/filepicker.js:19:20: (

It's null output. Any idea, in where I am doing mistake.

Thanks

@tdermendjiev
Copy link
Contributor

tdermendjiev commented Nov 27, 2017

@jibon57 mediaInfo.valueForKey(IQMediaTypeImage) should work then.

PS: Just tested it and it prints:
{ IQMediaImage = "<UIImage: 0x6040000ae880> size {4288, 2848} orientation 0 scale 1.000000"; }

@tdermendjiev tdermendjiev changed the title Retrive value from NSDictionary type Retrieve value from NSDictionary type Nov 27, 2017
@jibon57
Copy link
Author

jibon57 commented Nov 27, 2017

@tdermendjiev Thanks for your reply. I tried like bellow:

public mediaPickerControllerDidFinishMediaWithInfo(controller, info){
            let mediaInfo = info.copy();
            let data = mediaInfo.valueForKey(IQMediaTypeImage);
            console.log(data); 
        }

but same output:

CONSOLE LOG file:///app/tns_modules/nativescript-filepicker/filepicker.js:19:20: (

Will you please share your working code?

Thanks

@tdermendjiev
Copy link
Contributor

tdermendjiev commented Nov 27, 2017

@jibon57 it appears that it's a nativescript-cli related issue with printing multiline console logs which we are currently working on. If you run the project from XCode you will be able to see the full logs and respectively the proper ones. Here is the code of the ViewController I used to reproduce the issue:

class RootViewController extends UIViewController implements IQMediaPickerControllerDelegate {
	public static ObjCProtocols = [IQMediaPickerControllerDelegate];

	viewDidLoad() {
		console.log("Root loaded");
	}

	viewDidAppear() {
		let controller = IQMediaPickerController.alloc().init();
		controller.delegate = this;
		this.presentViewControllerAnimatedCompletion(controller, true, null);
	}

	mediaPickerControllerDidFinishMediaWithInfo(controller, info) {
		console.log(info.valueForKey("IQMediaTypeImage"));
	}

	mediaPickerControllerDidCancel(controller){
		console.log("Media picker canceled");
	}
}

How were you able to print the whole NSDictionary output from your first comment - by running from XCode or from the CLI?

P.S. Both objectForKey() and valueForKey() work. I was just testing with the presumption that objectForKey gets you a null output.

@jibon57
Copy link
Author

jibon57 commented Nov 27, 2017

@tdermendjiev Thank you so much !!! I thought my code has some problem that's why the output was null. I got the output of my first comment was from an older version of NativeScript. In XCode I am getting the complete output now. Now another questions... Can I use the value of IQMediaImage directly to show in view or uploading to remote server? Or how can I reuse that for view or upload?

@tdermendjiev
Copy link
Contributor

@jibon57 you can use the IQMediaImage value pretty much the same way you would use UIImage in a native function. For image uploading you can refer to this one. In case you are now able to properly print the desired values I will close this issue. If you have issues unrelated to the current, please open a new one.

@jibon57
Copy link
Author

jibon57 commented Nov 29, 2017

@tdermendjiev Thanks for your reply. Will you please give some hints to use the value of IQMediaImage? For example if I want to display the image in view. My original issue was, I wasn't able to display the selected image.

@tdermendjiev
Copy link
Contributor

In iOS the UIImageView class is used for images to be displayed. Let's say you have the instance variableimageView(UIImageView instance) and the IQMediaImage value assigned to the variable iqMediaImage(UIImage instance). The you set the imageView's image just like: imageView.image = iqMediaImage.

@jibon57 jibon57 closed this as completed Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants