zoukankan      html  css  js  c++  java
  • [iOS 高级] iOS远程推送与本地推送大致流程

    本地推送:

        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进行推送

    示意图:









  • 相关阅读:
    linux中编译C语言程序
    plsql 基础教程(二)
    plsql 基础教程(一)
    plsql开发笔记和小结
    表的约束
    一道面试题:说说进程和线程的区别
    HashTable实现原理
    HashMap、Hashtable、HashSet三种hash集合的区别
    Eclipse快捷键大全
    Statement、 PreparedStatement 、CallableStatement 区别和联系
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8681243.html
Copyright © 2011-2022 走看看