关闭

关于极光推送我做的工作

318人阅读 评论(0) 收藏 举报
分类:

  要做极光推送就要先在官网上注册信息,登录后创建应用,点击获得appKey, 如果是推送iOS,要在developer.apple.com苹果官网上注册开发者证书和生产者证书,这两个证书均为.p12证书,配置完证书如何导出p12呢,依次把这两个证书点一次,进入字符串钥匙如果点不开就用command + 空格输入key点击回车就OK了.然后在对应证书的地方(注意证书名称要导出与appId对应的bundleID的证书)点击右键,点击导出即可.极光创建应用这块完事了那就开始写代码吧.

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

    self.window.backgroundColor = [UIColorwhiteColor];

    NSString *advertisingId = [[[ASIdentifierManagersharedManager]advertisingIdentifier]UUIDString];

    if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 8.0)

    {

        //可以添加自定义categories

        [JPUSHServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];

        //[application registerUserNotificationSettings:]     

    } else

    {

        //categories 必须为nil

        [JPUSHServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert) categories:nil];

    }

    //Required   

    // 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。    

    [JPUSHServicesetupWithOption:launchOptionsappKey:@"appKey"channel:@"publish channel"apsForProduction:YESadvertisingIdentifier:advertisingId];   

    if (launchOptions) {

        NSDictionary *remoteNotification = [launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];        

        if (remoteNotification)

        {

            NSLog(@"推送消息==== %@",remoteNotification);            

            [selfgoToMssageViewControllerWith:remoteNotification];

        }

    }

    self.window.rootViewController = [[ADViewControlleralloc]init];

      [self.window makeKeyAndVisible];

    }

    returnYES ;

}

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

//    

/// Required - 注册 DeviceToken

    [JPUSHServiceregisterDeviceToken:deviceToken];

    if ([[[NSUserDefaultsstandardUserDefaults]objectForKey:@"myPhoneText"]length] !=0) {

        

        _Alisa = [[NSUserDefaultsstandardUserDefaults]objectForKey:@"myPhoneText"];

        

        [JPUSHServicesetAlias:_AlisacallbackSelector:nilobject:self];

    }

}


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {   

    [JPUSHServicehandleRemoteNotification:userInfo];

    application.applicationIconBadgeNumber =0;

 

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

{

     // IOS 7 Support Required

    [JPUSHServicehandleRemoteNotification:userInfo];  

    completionHandler(UIBackgroundFetchResultNewData); 

    NSDictionary *apn =[userInfovalueForKey:@"aps"];

    

    NSString *content = [apnvalueForKey:@"alert"];    

    NSUserDefaults*pushJudge = [NSUserDefaultsstandardUserDefaults];   

    [pushJudge setObject:contentforKey:@"content"];   

    NSLog(@"------+%@+-----",content);   

    [selfgoToMssageViewControllerWith:userInfo];

}

- (void)goToMssageViewControllerWith:(NSDictionary*)msgDic

{

    

    if ([[[NSUserDefaultsstandardUserDefaults]objectForKey:@"content"]length] !=0)

    {

        _Alert = [[NSUserDefaultsstandardUserDefaults]objectForKey:@"content"];       

            NSString *Repayment =@"【回款通知】";

            NSString *red =@"【红包】";

            NSString *interest =@"【加息卷】";        

        if ([_AlertrangeOfString:Repayment].location !=NSNotFound)

            {

            manageViewController *mvc = [[manageViewControlleralloc]init];        

            baseNavigationViewController *nav = [[baseNavigationViewControlleralloc]initWithRootViewController:mvc];        

            [self.window.rootViewControllerpresentViewController:navanimated:YEScompletion:nil];        

            }

            elseif ([_AlertrangeOfString:red].location !=NSNotFound)

            {

                couponsViewController *cvc = [[couponsViewControlleralloc]init];        

                baseNavigationViewController *nav =[[baseNavigationViewControlleralloc]initWithRootViewController:cvc];       

                [self.window.rootViewControllerpresentViewController:navanimated:YEScompletion:nil];        

            }

            elseif ([_AlertrangeOfString:interest].location !=NSNotFound)

            {

                interestViewController *ivc = [[interestViewControlleralloc]init];

                baseNavigationViewController *nav =[[baseNavigationViewControlleralloc]initWithRootViewController:ivc];

                [self.window.rootViewControllerpresentViewController:navanimated:YEScompletion:nil];

        }

    }

}

- (void)applicationDidEnterBackground:(UIApplication *)application

{


    if ([[[NSUserDefaultsstandardUserDefaults]objectForKey:@"content"]length] !=0)

    {

        _Alert = [[NSUserDefaultsstandardUserDefaults]objectForKey:@"content"];        

        NSString *Repayment =@"【还款通知】";

        NSString *red =@"【红包】";

        NSString *interest =@"【加息卷】";        

        if ([_AlertrangeOfString:Repayment].location !=NSNotFound)

        {

            manageViewController *mvc = [[manageViewControlleralloc]init];           

            baseNavigationViewController *nav = [[baseNavigationViewControlleralloc]initWithRootViewController:mvc];            

            [self.window.rootViewControllerpresentViewController:navanimated:YEScompletion:nil];            

        }

        elseif ([_AlertrangeOfString:red].location !=NSNotFound)

        {

            couponsViewController *cvc = [[couponsViewControlleralloc]init];            

            baseNavigationViewController *nav =[[baseNavigationViewControlleralloc]initWithRootViewController:cvc];           

            [self.window.rootViewControllerpresentViewController:navanimated:YEScompletion:nil];            

        }

        elseif ([_AlertrangeOfString:interest].location !=NSNotFound)

        {

            interestViewController *ivc = [[interestViewControlleralloc]init];

            baseNavigationViewController *nav =[[baseNavigationViewControlleralloc]initWithRootViewController:ivc];

            [self.window.rootViewControllerpresentViewController:navanimated:YEScompletion:nil];

        }

    }

    NSLog(@"\n程序进入后台");    

    [application setApplicationIconBadgeNumber:0];//清除角标

    [application cancelAllLocalNotifications];

}


- (void)applicationWillEnterForeground:(UIApplication *)application

{        

    [application setApplicationIconBadgeNumber:0];  //清除角标

    [application cancelAllLocalNotifications];

    NSLog(@"\n程序进入前台");  

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:815次
    • 积分:50
    • 等级:
    • 排名:千里之外
    • 原创:4篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类