Original: http://m.blog.csdn.net/article/details?id=38824551
1. First create a APNS certificate, linked as follows
Http://developer.easemob.com/docs/emchat/ios/push/certificate.html
After the certificate is created, make the certificate a p12 file and upload it to the ring background
2. Re-create the real Machine Debug certificate, and the description file, to ensure that the real machine debugging. and AppID to push the function again.
3. Binding the Ring letter certificate and Appkey
// register the name of the APNs file, need to upload the certificate with the background name one by one corresponding @" Chatdemo " ; [[Easemob sharedinstance] registersdkwithappkey:@ " 4545521 [Apnscertname:apnscertname]; [[Easemob sharedinstance] enablebackgroundreceivemessage]; [[Easemob sharedinstance] application:application didfinishlaunchingwithoptions:launchoptions];
4. Then several methods of implementing the ring letter
//Receive Message callback-(void) Didreceivemessage: (Emmessage *) message{#if! Target_iphone_simulator[self playsoundandvibration]; BOOL isappactivity= [[UIApplication sharedapplication] applicationstate] = =uiapplicationstateactive; if(!isappactivity) {[Self shownotificationwithmessage:message]; }#endif}- (void) playsoundandvibration{//Skip ringing if the last ringing and shaking time is too shortNSLog (@"%@, %@", [NSDate Date], self.lastplaysounddate); Nstimeinterval TimeInterval=[[NSDate Date] timeIntervalSinceDate:self.lastPlaySoundDate]; if(TimeInterval <kdefaultplaysoundinterval) { return; } //Save last ring timeSelf.lastplaysounddate =[NSDate Date]; //when a message is received, the audio is played[[Easemob Sharedinstance].devicemanager Asyncplaynewmessagesound]; //when the message is received, the vibration[[Easemob Sharedinstance].devicemanager asyncplayvibration];}- (void) Shownotificationwithmessage: (Emmessage *) message{ID<IEMMessageBody> MessageBody =[Message.messagebodies Firstobject]; NSString*messagestr =Nil; Switch(messagebody.messagebodytype) { Caseemessagebodytype_text: {messagestr= ((Emtextmessagebody *). messagebody). Text; } Break; Caseemessagebodytype_image: {messagestr=@"[Image]"; } Break; Caseemessagebodytype_location: {messagestr=@"[Location]"; } Break; Caseemessagebodytype_voice: {messagestr=@"[Audio]"; } Break; Caseemessagebodytype_video:{messagestr=@"[VIDEO]"; } Break; default: Break; } //Send local pushUilocalnotification *notification =[[Uilocalnotification alloc] init]; Notification.firedate= [NSDate Date];//time the notification was triggeredNSString*title =Message.from; if(message.isgroup) {Nsarray*grouparray =[[Easemob Sharedinstance].chatmanager grouplist]; for(Emgroup *groupinchGrouparray) { if([group.groupid IsEqualToString:message.conversation.chatter]) {title= [NSString stringWithFormat:@"%@(%@)", Message.groupsendername, Group.groupsubject]; Break; } }} notification.alertbody= [NSString stringWithFormat:@"%@:%@", title, Messagestr]; Notification.alertaction=@"Open"; Notification.timezone=[Nstimezone Defaulttimezone]; Notification.soundname=Uilocalnotificationdefaultsoundname; //Send Notifications[[UIApplication sharedapplication] schedulelocalnotification:notification]; UIApplication*application =[UIApplication sharedapplication]; Application.applicationiconbadgenumber+=1;}
This will allow you to push the message.
IOS: Push of ring letter