Steps for IP network requests (WHH for your own reference only)

Source: Internet
Author: User

The process is roughly like this:

1 adding notifications

2 Sending a network request there is an action to send a notification

3 perform specific actions to send notifications

The code is as follows:

1 Add notification in VC

[[Nsnotificationcenter defaultcenter] addobserver:self                                             selector: @selector (receivingYM1:)                                                 Name: @" YM1 " Object : nil];   

2 Sending notifications in SYNDISPATCHPROCESSOR.M

-(void) delaytimegcdbuild{//NSLog (@ "main thread%@", [Nsthread CurrentThread]); //interval or 1 seconds?uint64_t interval =1* Nsec_per_sec/ - ; //Create a GCD queue that specifically executes the timer callback//dispatch_queue_t queue = dispatch_queue_create ("My Queue", 0);dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default,0); //Create a timer_timer = Dispatch_source_create (Dispatch_source_type_timer,0,0, queue); //set the timer parameter using the Dispatch_source_set_timer functionDispatch_source_set_timer (_timer, Dispatch_time (Dispatch_time_now,0), Interval,0); //Set CallbackDispatch_source_set_event_handler (_timer, ^() {[Self.arraylockLock]; if([Protocolmutablearrays count]>0) {NSData* Ndata = [Protocolmutablearrays objectatindex:0]; //NSLog (@ "Hava received Datas is-----:%@", [self ndatatogbkstring:ndata]);nsdata* d = [Ndata subdatawithrange:nsmakerange (5,3)]; NSString* AStr =[[NSString alloc] initwithdata:d encoding:nsasciistringencoding]; NSLog (@"here is the type of judgment:%@", ASTR); {                                //send a notification here[[Nsnotificationcenter Defaultcenter] Postnotificationname:astrObject: [Ndata Subdatawithrange:nsmakerange (Ten, ndata.length-Ten)]]; } [protocolmutablearrays Removeobjectatindex:0];            } [Self.arraylock unlock]; });

3 performing events that send notifications

//receive comic data after sending out notifications- (void) ReceivingYM1: (nsnotification*) anotification{//received a large picture of the 4 cells of the comic with some related informationnsdata* NSData = [anotificationObject]; NSString*string=[[NSString Alloc]initwithdata:nsdata encoding:nsutf8stringencoding]; NSLog (@"nsdata:%@",string); [Self Performselectoronmainthread: @selector (updateResgContollerYM1:) Withobject:nsdata waituntildone:yes];}//updated Humor Square Comics UI-(void) UpdateResgContollerYM1: (ID) data{//converting data into a dictionary typensdictionary* ym1dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil]; //receive with an arrayNsmutablearray *commicarr = [ym1dict valueforkey:@"comiclist"]; //to save data in a dictionarySelf. Fircomicdic = [Commicarr objectatindex:0]; Self. Sndcomicdic= [Commicarr Objectatindex:1]; Self. Thdcomicdic= [Commicarr Objectatindex:2]; Self. Fourthcomicdic= [@{@"comiccontent":@"alcoholic",@"Comicid":@"4"} mutablecopy];}

Steps for IP network requests (WHH for your own reference only)

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.