How does IOS get a parameter value after a function has finished executing the code below him?

Source: Internet
Author: User

Recent projects involving OC and H5 interaction, one of the problems is H5 load album photos, the method is generally: and the background to make a good protocol, in the request to intercept the protocol, and then pass a relative address to H5 to load local images.

When interacting, H5 calls the OC registration method, callback the relative address of the photo passed by OC to load the phone photo. There is a problem here, to do H5 synchronous loading of the picture of the phone, it is not easy, because the method of calling OC registration, it is necessary to return the relative address of the picture, too late to wait for user operation, it is necessary to return the address. So we have to find a way to execute the user's operation, get the relative path and then pass to H5, here will first execute the user's selection of photos or take photos of the program, get the path and then go to execute the callback function.

Workaround:

1[_bridge Registerhandler:@"AddImage"handler:^(ID data, Wvjbresponsecallback responsecallback) {2         3dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_high,0);4_group =dispatch_group_create ();5         6Dispatch_sync (queue,^{7             //ensure thread order8 Dispatch_group_enter (_group);9             //Loading PicturesTen [self addimage]; One         }); A  -         //Summary -Dispatch_group_notify (_group, queue, ^{ the             //Here again to H5 page callback, address parameter _imagesource have value - Responsecallback (_imagesource); -         }); +}];

The code, as shown above, is added to a group, into group Dispatch_group_enter (_group), after execution ( success or failure to leave)groupDispatch_group_ Leave(_group).

Be careful not to use asynchronous, tested, asynchronous call the album's cue box when there is a delay of about 10 seconds!

How does IOS get a parameter value after a function has finished executing the code below him?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.