第一步:申请证书:app
第二步:申请app ids,应用名字必须一致。而后再进入进行编辑,使其enable,绿灯。ide
第三步:申请provisioning profile,生成.mobileprovision,双击该证书才能正确导入手机设备,不能拖。spa
第四步:建立应用,使其名字一致。3d
第五步:写代码orm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsip
{rem
// Override point for customization after application launch.string
// return YES;it
UIRemoteNotificationType types =io
(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert);
//注册消息推送
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:types];
return YES;
}
//获取DeviceToken成功
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"DeviceToken: {%@}",deviceToken);
//这里进行的操做,是将Device Token发送到服务端
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"DeviceToken:%@",deviceToken] delegate:self cancelButtonTitle:nil otherButtonTitles:@"肯定", nil];
[alert show];
}
//注册消息推送失败
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Register Remote Notifications error:{%@}",error);
// NSLog(@"Register Remote Notifications error:{%@}",error.localizedDescription);
}
//处理收到的消息推送
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Receive remote notification : %@",userInfo);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"舒适提示"
message:@"推送成功!"
delegate:nil
cancelButtonTitle:@"肯定"
otherButtonTitles:nil];
[alert show];
}