Ios8 iOS应用程序未注册推送通知
我正在尝试在iOS应用程序中注册推送通知。但它既不调用使用DeviceToken的Ios8 iOS应用程序未注册推送通知,ios8,push-notification,apple-push-notifications,Ios8,Push Notification,Apple Push Notifications,我正在尝试在iOS应用程序中注册推送通知。但它既不调用使用DeviceToken的DidRegister进行远程通知,也不调用使用错误回调方法的DidFailToRegister进行远程通知。我已撤销并重新生成应用程序的配置文件 我正在使用iOS8,并且在我的Info.plist中启用了以下后台模式 应用程序注册位置更新 应用程序下载内容以响应推送通知 应用程序从网络下载内容 代码是: -(void) application:(UIApplication *)application didFai
DidRegister进行远程通知,也不调用使用错误回调方法的DidFailToRegister进行远程通知。我已撤销并重新生成应用程序的配置文件
我正在使用iOS8,并且在我的Info.plist中启用了以下后台模式
应用程序注册位置更新
应用程序下载内容以响应推送通知
应用程序从网络下载内容
代码是:
-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Failed to register for push");
}
-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"did succeed in register for push");
// Get the device token string
const char* data = [deviceToken bytes];
NSMutableString* token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:@"%02.2hhX", data[i]];
}
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self respondToEventNotification:userInfo];
}
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[self respondToEventNotification:userInfo];
}
-(void)应用程序:(UIApplication*)应用程序未能注册远程通知错误:(NSError*)错误{
NSLog(@“无法注册推送”);
}
-(无效)应用程序:(UIApplication*)应用程序DIdRegisterForRemotionTificationswithDeviceToken:(NSData*)deviceToken{
NSLog(@“已成功注册推送”);
//获取设备令牌字符串
常量字符*数据=[deviceToken字节];
NSMutableString*标记=[NSMutableString];
对于(int i=0;i<[deviceToken length];i++){
[令牌格式:@“%02.2hhX”,数据[i]];
}
[[NSUserDefaults standardUserDefaults]setObject:token forKey:@“DeviceToken”];
[[NSUserDefaults standardUserDefaults]同步];
}
-(无效)应用程序:(UIApplication*)应用程序DidReceiveMemotentification:(NSDictionary*)用户信息{
[自我响应事件通知:userInfo];
}
-(void)application:(UIApplication*)application didReceiveMemotentification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler{
[自我响应事件通知:userInfo];
}
您是否已使用didfishlaunchwithoptions
方法注册您的应用程序,如
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
您必须考虑IOS8中推送通知的注册过程。
这可能会对您有所帮助。参考您是否为开发者帐户中的appid启用了pushnotifications选项?它起作用了。虽然我不得不使用UIUserNotificationTypeSound
作为UIRemoteNotificationBadge
等都不推荐使用