美文网首页
极光推送Use of undeclared identifier

极光推送Use of undeclared identifier

作者: 复古先生 | 来源:发表于2017-11-02 11:19 被阅读0次

    极光推送申请好了,配置IOS配置中报错了,找不到kJPFDidReceiveRemoteNotification

    暂时处理方式:暂时找不到的库名就用这个 原生写法

    如下内容:

    // ---------------------------------------------------------------------------------

    - (void)applicationWillResignActive:(UIApplication*)application {

    }

    - (void)applicationDidEnterBackground:(UIApplication*)application {

    [[UIApplicationsharedApplication]setApplicationIconBadgeNumber:0];

    }

    - (void)applicationWillEnterForeground:(UIApplication*)application {

    [applicationsetApplicationIconBadgeNumber:0];

    [applicationcancelAllLocalNotifications];

    }

    - (void)applicationDidBecomeActive:(UIApplication*)application {

    }

    - (void)applicationWillTerminate:(UIApplication*)application {

    }

    // ---------------------------------------------------------------------------------

    #pragma mark - 注册推送回调获取 DeviceToken

    #pragma mark -- 成功

    - (void)application:(UIApplication*)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

    {

    // 注册成功

    // 极光: Required - 注册 DeviceToken

    [JPUSHServiceregisterDeviceToken:deviceToken];

    }

    #pragma mark -- 失败

    - (void)application:(UIApplication*)applicationdidFailToRegisterForRemoteNotificationsWithError:(NSError*)error

    {

    // 注册失败

    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);

    }

    // ---------------------------------------------------------------------------------

    // 这部分是官方demo里面给的, 也没实现什么功能, 放着以备不时之需

    #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

    - (void)application:(UIApplication*)applicationdidRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings

    {

    }

    // Called when your app has been activated by the user selecting an action from

    // a local notification.

    // A nil action identifier indicates the default action.

    // You should call the completion handler as soon as you've finished handling

    // the action.

    - (void)application:(UIApplication*)applicationhandleActionWithIdentifier:(NSString*)identifierforLocalNotification:(UILocalNotification*)notificationcompletionHandler:(void(^)())completionHandler

    {

    }

    // Called when your app has been activated by the user selecting an action from

    // a remote notification.

    // A nil action identifier indicates the default action.

    // You should call the completion handler as soon as you've finished handling

    // the action.

    - (void)application:(UIApplication*)applicationhandleActionWithIdentifier:(NSString*)identifierforRemoteNotification:(NSDictionary*)userInfocompletionHandler:(void(^)())completionHandler

    {

    }

    #endif

    // ---------------------------------------------------------------------------------

    - (void)application:(UIApplication*)applicationdidReceiveLocalNotification:(UILocalNotification*)notification

    {

    [JPUSHServiceshowLocalNotificationAtFront:notificationidentifierKey:nil];

    }

    // ---------------------------------------------------------------------------------

    #pragma mark - iOS7: 收到推送消息调用

    - (void)application:(UIApplication*)applicationdidReceiveRemoteNotification:(NSDictionary*)userInfofetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {

    // iOS7之后调用这个

    [JPUSHServicehandleRemoteNotification:userInfo];

    NSLog(@"iOS7及以上系统,收到通知");

    if([[UIDevicecurrentDevice].systemVersionfloatValue] <10.0|| application.applicationState>0)

    {

    // 程序在前台或通过点击推送进来的会弹这个alert

    NSString*message = [NSStringstringWithFormat:@"iOS7-8-9收到的推送%@", [userInfo[@"aps"]objectForKey:@"alert"]];

    UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:messagedelegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nilnil];

    [alertshow];

    }

    completionHandler(UIBackgroundFetchResultNewData);

    }

    // ---------------------------------------------------------------------------------

    #pragma mark - iOS10: 收到推送消息调用(iOS10是通过Delegate实现的回调)

    #pragma mark- JPUSHRegisterDelegate

    #ifdef NSFoundationVersionNumber_iOS_9_x_Max

    // 当程序在前台时, 收到推送弹出的通知

    - (void)jpushNotificationCenter:(UNUserNotificationCenter*)centerwillPresentNotification:(UNNotification*)notificationwithCompletionHandler:(void(^)(NSInteger))completionHandler {

    NSDictionary* userInfo = notification.request.content.userInfo;

    if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]])

    {

    [JPUSHServicehandleRemoteNotification:userInfo];

    NSString*message = [NSStringstringWithFormat:@"will%@", [userInfo[@"aps"]objectForKey:@"alert"]];

    NSLog(@"iOS10程序在前台时收到的推送: %@", message);

    UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:messagedelegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nilnil];

    [alertshow];

    }

    completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以设置

    }

    // 程序关闭后, 通过点击推送弹出的通知

    - (void)jpushNotificationCenter:(UNUserNotificationCenter*)centerdidReceiveNotificationResponse:(UNNotificationResponse*)responsewithCompletionHandler:(void(^)())completionHandler {

    NSDictionary* userInfo = response.notification.request.content.userInfo;

    if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]])

    {

    [JPUSHServicehandleRemoteNotification:userInfo];

    NSString*message = [NSStringstringWithFormat:@"did%@", [userInfo[@"aps"]objectForKey:@"alert"]];

    NSLog(@"iOS10程序关闭后通过点击推送进入程序弹出的通知: %@", message);

    UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:messagedelegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nilnil];

    [alertshow];

    }

    completionHandler();// 系统要求执行这个方法

    }

    #endif

    相关文章

      网友评论

          本文标题:极光推送Use of undeclared identifier

          本文链接:https://www.haomeiwen.com/subject/lnvgpxtx.html