ios - 使用 Parse SDK for IOS 推送未在设备中交付
<p><p>我正在使用 parse SDK 向 friend 发送推送通知。
注意:我已经使用简单的 REST API 手动测试了推送通知证书,它在那里工作。</p>
<p>使用以下代码:
我在安装表中, channel 是数组类型,我已经匹配了键:
它在解析表中显示删除器,但我的设备没有收到任何类型的通知(请查看随附的屏幕截图)</p>
<pre><code> PFQuery * pushQuery = ;
;
NSString * alert = .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 {
} }];
</code></pre>
<p>我的委托(delegate)设置:</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)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.
;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
PFInstallation *currentInstallation = ;
;
currentInstallation.channels = @[@“channel”];
;
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
if (error.code == 3010) {
//NSLog(@"Push notifications are not supported in the iOS Simulator.");
} else {
// show some alert or otherwise handle the failure to register.
//NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
;
}
//NOTE: after login i change the channels value in installation table by
PFInstallation *currentInstallation = ;
// ;
NSString *string=];
NSArray *array=;
currentInstallation.channels =array;
;
</code></pre>
<p> <img src="/image/Yu14B.png" alt="enter image description here"/> </p>
<p> <img src="/image/1hGI8.png" alt="enter image description here"/> </p>
<p><strong>更新:使用适用于 IOS 8 的新 Parse SDK,我的问题已解决</strong></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果您的设备运行 iOS 8,请注意 <code>registerForRemoteNotificationTypes</code> 不再受支持。</p>
<p>您需要使用 <code>registerUserNotificationSettings</code>。这是一个适用于 iOS 7(及以下)和 iOS 8 的示例代码:</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Checks for iOS 8
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)) {
];
;
} else {
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
// The rest of your didFinishLaunchingWithOptions: method should be here
return YES;
}
</code></pre>
<hr/>
<p><strong>编辑:</strong>我刚刚看到你说它与 REST API 一起工作,所以这不会导致你的问题。不过,最好将您的代码更新为此,因为您可能会在使用 iOS 8 设备时遇到问题。</p>
<hr/>
<p><strong>编辑 2:</strong></p>
<p>问题可能来自您的 Parse 项目配置。您需要手动启用“客户端推送通知”。默认情况下,Parse 将其禁用,从而阻止 Parse SDK 发送推送通知。</p>
<p>转到 Parse.com,进入应用程序的设置,在推送部分中,设置“启用客户端推送?”改为"is"。</p></p>
<p style="font-size: 20px;">关于ios - 使用 Parse SDK for IOS 推送未在设备中交付,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26650965/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26650965/
</a>
</p>
页:
[1]