• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 使用 Parse SDK for IOS 推送未在设备中交付

[复制链接]
菜鸟教程小白 发表于 2022-12-12 12:24:29 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 parse SDK 向 friend 发送推送通知。 注意:我已经使用简单的 REST API 手动测试了推送通知证书,它在那里工作。

使用以下代码: 我在安装表中, channel 是数组类型,我已经匹配了键: 它在解析表中显示删除器,但我的设备没有收到任何类型的通知(请查看随附的屏幕截图)

 PFQuery * pushQuery = [PFInstallation query];
[pushQuery whereKey"channels" containedIn:array];
NSString * alert = [NSString stringWithFormat"You have a new message from %@!", [PFUser currentUser].username]; 
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                          alert, @"alert",
                          @"default", @"sound",
                          @"Increment", @"badge",
                          nil]; [PFPush sendPushDataToQueryInBackground:pushQuery withData:data block:^(BOOL succeeded, NSError *error) {
        if (!error) {

        }
        else {
        } }];

我的委托(delegate)设置:

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {

    // Uncomment and fill in with your Parse credentials:
    [Parse setApplicationId“MY APP ID
                  clientKey“MY CLIENT KEY”];

   // Override point for customization after application launch.
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];

}



- (void)applicationUIApplication *)application didRegisterForRemoteNotificationsWithDeviceTokenNSData *)newDeviceToken {
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:newDeviceToken];
    currentInstallation.channels = @[@“channel”];
    [currentInstallation saveInBackground];


   }


- (void)applicationUIApplication *)application didFailToRegisterForRemoteNotificationsWithErrorNSError *)error {
    if (error.code == 3010) {
        //NSLog(@"ush notifications are not supported in the iOS Simulator.");
    } else {
        // show some alert or otherwise handle the failure to register.
        //NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
    }
}

- (void)applicationUIApplication *)application didReceiveRemoteNotificationNSDictionary *)userInfo {
    [PFPush handlePush:userInfo];


}

//NOTE: after login i change the channels value in installation table by 

   PFInstallation *currentInstallation = [PFInstallation currentInstallation];
       // [currentInstallation setDeviceTokenFromData:newDeviceToken];

        NSString *string=[NSString stringWithFormat"channel%@",[PFUser currentUser]];
        NSArray *array=[NSArray arrayWithObjects:string, nil];
        currentInstallation.channels =array;
        [currentInstallation saveInBackground];

enter image description here

enter image description here

更新:使用适用于 IOS 8 的新 Parse SDK,我的问题已解决



Best Answer-推荐答案


如果您的设备运行 iOS 8,请注意 registerForRemoteNotificationTypes 不再受支持。

您需要使用 registerUserNotificationSettings。这是一个适用于 iOS 7(及以下)和 iOS 8 的示例代码:

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary*)launchOptions {

    // Checks for iOS 8
    if ([application respondsToSelectorselector(isRegisteredForRemoteNotifications)) {

           [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

           [application registerForRemoteNotifications];

    } else {

          [application registerForRemoteNotificationTypes:
                     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];

    }

    // The rest of your didFinishLaunchingWithOptions: method should be here

    return YES;
}

编辑:我刚刚看到你说它与 REST API 一起工作,所以这不会导致你的问题。不过,最好将您的代码更新为此,因为您可能会在使用 iOS 8 设备时遇到问题。


编辑 2:

问题可能来自您的 Parse 项目配置。您需要手动启用“客户端推送通知”。默认情况下,Parse 将其禁用,从而阻止 Parse SDK 发送推送通知。

转到 Parse.com,进入应用程序的设置,在推送部分中,设置“启用客户端推送?”改为"is"。

关于ios - 使用 Parse SDK for IOS 推送未在设备中交付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26650965/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap