本地推送:

    UILocalNotification *notification=[[UILocalNotification alloc] init];
    if (notification!=nil) {
        NSDate *now=[NSDate new];
        notification.fireDate=[now dateByAddingTimeInterval:60];//60秒后通知
        notification.repeatInterval=0;//循环次数
        notification.timeZone=[NSTimeZone defaultTimeZone];
        notification.applicationIconBadgeNumber=1; //应用的红色数字
        notification.soundName= UILocalNotificationDefaultSoundName;//声音
        notification.alertBody=@"通知内容";//提示信息 弹出提示框
        notification.alertAction = @"打开";  //提示框button
        //notification.hasAction = NO; //是否显示额外的button。为no时alertAction消失
        
        // NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
        //notification.userInfo = infoDict; //加入额外的信息
        
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        
    }
推送过后。假设应用处于后台状态,可实现代理方法来进行想要的操作

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

}

假设应用已退出。这时候要在以下的方法中来取出推送并处理

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    
    UILocalNotification * push=[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];//取出推送对象

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}



远程推送的大致流程例如以下:

1.使用appId注冊推送服务

2.获得推送用的token

3.app上传token到自己的server

4.自己的server将推送信息和token发送给apns

5.apns进行推送

示意图:[iOS 高级] iOS远程推送与本地推送大致流程_ico