我的应用程序已在iTunes Connect中显示。为iOS 10
提供支持,我使用的是上次版本中使用的certificate
和provisioning
。目前,我的XCode
版本 8.1 (8B62)
。我正在开发中接收远程通知。但是当我在TestFlight
中测试应用时,我没有收到任何远程通知。但是iOS 9
与XCode 7
一起工作正常。
这是我的AppDelegate.h
#import <UIKit/UIKit.h>
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@import UserNotifications;
#endif
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
#else
@interface AppDelegate : UIResponder <UIApplicationDelegate>
#endif
@property (strong, nonatomic) UIWindow *window;
@property (copy ,nonatomic) void(^backgroundSessionCompletionHandler)();
@end
// Copied from Apple's header in case it is missing in some cases (e.g. pre-Xcode 8 builds).
#ifndef NSFoundationVersionNumber_iOS_9_x_Max
#define NSFoundationVersionNumber_iOS_9_x_Max 1299
#endif
这是我的AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
#pragma mark - Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initPushnotificationService];
[self decideViewController];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// SOME CODE
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// SOME CODE
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// SOME CODE
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// SOME CODE
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// SOME CODE
}
- (void)application:(UIApplication *)app
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
{
// SOME CODE
}
- (void)application:(UIApplication *)app
didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
// SOME CODE
}
- (void)application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
forLocalNotification:(UILocalNotification *)notification
withResponseInfo:(NSDictionary *)responseInfo
completionHandler:(void (^)())completionHandler{
// SOME CODE
}
- (void)application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
forRemoteNotification:(UILocalNotification *)notification
withResponseInfo:(NSDictionary *)responseInfo
completionHandler:(void (^)())completionHandler{
// SOME CODE
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// SOME CODE
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
// SOME CODE
}
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#pragma mark -
#pragma mark - UNUserNotificationCenterDelegate
#pragma mark FOREGROUND Delegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
// SOME CODE
}
#pragma mark BACKGROUND Delegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
// SOME CODE
}
#endif
#pragma mark - push notification setup
-(void)initPushnotificationService{
UIMutableUserNotificationAction *viewMessageAction;
viewMessageAction = [[UIMutableUserNotificationAction alloc] init];
[viewMessageAction setActivationMode:UIUserNotificationActivationModeBackground];
[viewMessageAction setTitle:@"Say OK"];
[viewMessageAction setIdentifier:NotificationActionSayOkMessage];
[viewMessageAction setDestructive:NO];
[viewMessageAction setAuthenticationRequired:NO];
UIMutableUserNotificationAction *replyMessageAction;
if( __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0){
replyMessageAction = [[UIMutableUserNotificationAction alloc] init];
[replyMessageAction setActivationMode:UIUserNotificationActivationModeBackground];
[replyMessageAction setTitle:@"Reply"];
[replyMessageAction setBehavior:UIUserNotificationActionBehaviorTextInput];
[replyMessageAction setIdentifier:NotificationActionReplyMessage];
[replyMessageAction setDestructive:NO];
[replyMessageAction setAuthenticationRequired:NO];
}
else{
replyMessageAction = [[UIMutableUserNotificationAction alloc] init];
[replyMessageAction setActivationMode:UIUserNotificationActivationModeForeground];
[replyMessageAction setTitle:@"Reply"];
[replyMessageAction setIdentifier:NotificationActionReplyMessage];
[replyMessageAction setDestructive:NO];
[replyMessageAction setAuthenticationRequired:NO];
}
UIMutableUserNotificationCategory *viewMessageActionactionCategory;
viewMessageActionactionCategory = [[UIMutableUserNotificationCategory alloc] init];
[viewMessageActionactionCategory setIdentifier:NotificationCategoryViewMessage];
[viewMessageActionactionCategory setActions:@[viewMessageAction, replyMessageAction]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:viewMessageActionactionCategory];
// Register for remote notifications
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
/// iOS 7.1 or earlier. Disable the deprecation warnings.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
#pragma clang diagnostic pop
}
else
{ /// iOS 8 or later
// [START register_for_notifications]
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else{
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:authOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if( !error ){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
@try {
UNNotificationAction *sayOkMessageAction = [UNNotificationAction actionWithIdentifier:NotificationActionSayOkMessage title:@"Say OK" options:UNNotificationActionOptionAuthenticationRequired];
UNTextInputNotificationAction *replyMessageAction = [UNTextInputNotificationAction actionWithIdentifier:NotificationActionReplyMessage title:@"Reply" options:UNNotificationActionOptionAuthenticationRequired textInputButtonTitle:@"Reply" textInputPlaceholder:@"Message"];
UNNotificationCategory *messageCategory = [UNNotificationCategory categoryWithIdentifier:NotificationCategoryViewMessage actions:@[sayOkMessageAction,replyMessageAction] intentIdentifiers:@[NotificationActionSayOkMessage,NotificationActionReplyMessage] options:UNNotificationCategoryOptionCustomDismissAction];
NSSet *categories_set = [NSSet setWithObject:messageCategory];
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories_set];
/// For iOS 10 display notification (sent via APNS)
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
}
@catch (NSException *exception) {
NSLog(@"%@",exception);
}
}
];
#endif
}
}
}
@end
答案 0 :(得分:0)
检查PushNotification证书。它们被撤销或者可能未正确创建,或者您使用错误的证书进行分发。
答案 1 :(得分:0)
如果推送无法在生产模式下运行,我将遵循以下步骤
确保您的SANDBOX已关闭
询问开发者&amp;确保他们使用生产aps文件
确保在添加推送通知设置后创建了配置文件。
通常我发现Option 1
是他们没有做的。
如果选项1,2,3很好,请从您的结尾检查是否有编码。
答案 2 :(得分:0)
@ soumenSardar - 对于新的xode 8.1,您必须添加权利文件
目标---&gt;功能和验证推送通知在该视图上都是正确的 - &gt;解决它。
应该有效
小心推送通知在xcode 8.1中默认关闭
答案 3 :(得分:0)