IOS: Push of ring letter

Source: Internet
Author: User

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

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.