zoukankan      html  css  js  c++  java
  • iOS推送

    1.注册推送

    - (BOOL)pushNotificationOpen
    {
        if (isAfterIOS8)
        {
            UIUserNotificationType types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
            return (types & UIRemoteNotificationTypeAlert);
        }
        else
        {
            UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
            return (types & UIRemoteNotificationTypeAlert);
        }
    }
    View Code
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [self initvalues];
        if (isAfterIOS8)
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
                                                                                     settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
                                                                                     categories:nil]];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
                 (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }
        
        if (![self pushNotificationOpen])
        {
            self.localDeviceToken=@"ios_devicetoken_disabled";
        }
        
        NSDictionary * userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if(userInfo)
        {
            self.launchFromNotigication=YES;
            [self createPushViewIndexWithDic:userInfo];
        }
    }
    View Code
    -(void)createPushViewIndexWithDic:(NSDictionary *)userInfo
    {
        NSString*str=[[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
        NSString*rent=@"发财圈";
        NSString*second=@"房源";
        NSString*chatMsg=@"消息";
        
        NSRange range1 = [[str uppercaseString] rangeOfString:[rent uppercaseString]];
        if (range1.location!=NSNotFound)
        {
            self.pushViewIndex=3;
        }
        
        NSRange range2 = [[str uppercaseString] rangeOfString:[second uppercaseString]];
        if (range2.location!=NSNotFound)
        {
            self.pushViewIndex=3;
        }
        
        NSRange range3 = [[str uppercaseString] rangeOfString:chatMsg];
        if (range3.location!=NSNotFound)
        {
            self.pushViewIndex=2;
        }
    }
    View Code

    2.获得消息

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSString* tokeStr = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
        NSMutableString *mstr = [NSMutableString stringWithString:tokeStr];
        NSRange range = [mstr rangeOfString:@" "];
        while (range.location != NSNotFound)
        {
            [mstr deleteCharactersInRange:range];
            range = [mstr rangeOfString:@" "];
        }
        tokeStr=[NSString stringWithString:mstr];
        
        if ([tokeStr isEqualToString:@""] || !tokeStr)
        {
            tokeStr=@"ios_devicetoken_disabled";
        }
        self.localDeviceToken=tokeStr;
    }
    -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
        NSLog(@"注册失败");
    }
    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
        [HttpRequest httpRequestGetNewStsate];
        if (self.tabbarView!=nil)
        {
            if (self.becomeForground==NO||self.appActive==NO||self.launchFromNotigication==YES)
            {
                self.becomeForground=YES;
                NSString*str=[[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
                NSString*snsStr=@"发财圈";
                NSString*rent=@"个人租房";
                NSString*second=@"个人二手房";
                NSString*chatMsg=@"消息";
                
                NSRange range1 = [[str uppercaseString] rangeOfString:[rent uppercaseString]];
                if (range1.location!=NSNotFound)
                {
                    self.rentRed=YES;
                    
                    self.getPush=YES;
                    self.tabbarView.selectedIndex=3;
                    [self.tabbarView.foundNaviVC popToRootViewControllerAnimated:YES];
                }
                
                NSRange range2 = [[str uppercaseString] rangeOfString:[second uppercaseString]];
                if (range2.location!=NSNotFound)
                {
                    self.secondRed=YES;
                    
                    self.getPush=YES;
                    self.tabbarView.selectedIndex=3;
                    [self.tabbarView.foundNaviVC popToRootViewControllerAnimated:YES];
                }
                
                NSRange range3 = [[str uppercaseString] rangeOfString:chatMsg];
                if (range3.location!=NSNotFound)
                {
                    self.mustRefreshFriendList=YES;
                    
                    self.getPush=YES;
                    self.tabbarView.selectedIndex=2;
                    [self.tabbarView.messageNaviVC popToRootViewControllerAnimated:YES];
                }
                
                NSRange range4 = [[str uppercaseString] rangeOfString:snsStr];
                if (range4.location!=NSNotFound)
                {
                    self.getPush=YES;
                    self.tabbarView.selectedIndex=3;
                    [self.tabbarView.foundNaviVC popToRootViewControllerAnimated:YES];
                }
                
            }else
            {
                [ProgressHUD showSuccess:@"收到新的消息"];
            }
        }
    }
    View Code
  • 相关阅读:
    更好一点的:Vue 利用指令实现禁止反复发送请求
    实现一个深度比较
    Zrender:实现波浪纹效果
    Echarts:实现拖拽效果
    找到树中指定id的所有父节点
    Vue 利用指令实现禁止反复发送请求
    我对组件化的一点细琐的想法
    转盘式旋转抽奖
    信息系统与信息化
    跳出牢笼,逃出生天
  • 原文地址:https://www.cnblogs.com/liaods/p/4828897.html
Copyright © 2011-2022 走看看