IOS 结合个推实现推送问题

来源:互联网 发布:好玩的页游推荐知乎 编辑:程序博客网 时间:2024/04/30 16:47

一、准备工作

1、一台mac

2、一部iphone

3、苹果开发者认证的账号

二、开始

1、用mac申请一个CertificateSigningRequest.certSigningRequest,这个步骤百度一大堆。

2、苹果开发者中心管理后台,新建app,勾选apns服务,第一个是开发模式,第二个是产品模式,根据提示可以得到.cer文件,

      mac上双击,加入秘钥管理器中,再右键导出p12文件,这个文件是个推平台要用的。

3、新建证书,根据提示一路走,最后得到一个.cer文件,mac上双击,加入密钥管理器,再右键导出p12文件,这是发布app要用的。这个文件要和上边那个对应,都为开发模式或都为产品模式。

4、属性文件,新增,根据提示操作就行了,最后得到.mobileprovision文件,发布app使用的。


 public static string APNsPushToSingle(string title,string content,string token)        {            APNTemplate template = new APNTemplate();            APNPayload apnpayload = new APNPayload();            DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();            alertMsg.Body = content;         //通知文本消息字符串            alertMsg.ActionLocKey = "";            alertMsg.LocKey = "";            alertMsg.addLocArg("");            alertMsg.LaunchImage = "";//指定启动界面图片名            //IOS8.2支持字段            alertMsg.Title = title;     //通知标题            alertMsg.TitleLocKey = "";            alertMsg.addTitleLocArg("");            apnpayload.AlertMsg = alertMsg;            apnpayload.Badge = 1;//应用icon上显示的数字            apnpayload.ContentAvailable = 1;//推送直接带有透传数据            apnpayload.Category = "";            apnpayload.Sound = "";//通知铃声文件名            apnpayload.addCustomMsg("", "");//增加自定义的数据            template.setAPNInfo(apnpayload);            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);            /*单个用户推送接口*/            SingleMessage Singlemessage = new SingleMessage();            Singlemessage.Data = template;            String pushResult = push.pushAPNMessageToSingle(APPID, token, Singlemessage);            Console.Out.WriteLine(pushResult);            return pushResult;                   }


推送成功返回:
{"taskId":"OSAPNS-0222_sWuNF6FsJE7ilfijXLv0D6","result":"ok"}




0 0