您的位置:首页 > 移动开发 > IOS开发

IOS 结合个推实现推送问题

2016-02-22 11:52 232 查看
一、准备工作

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"}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: