[英]iOS 10 device , not receiving notification in production mode, but development is working
我的应用程序位于iTunes Connect中。 为了提供对iOS 10
支持,我使用了与上一版本相同的certificate
和provisioning
。 目前,我的XCode
版本是8.1 (8B62)
。 我正在开发中接收远程通知。 但是,当我在TestFlight
测试应用程序时,我没有收到任何远程通知。 但是它在使用XCode 7
iOS 9
上运行良好。
这是我的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
检查您的PushNotification证书。 它们被吊销了,或者创建不正确,或者您使用了错误的证书进行分发。
如果推送在生产模式下不起作用,请按照以下步骤进行操作
确保您的沙盒已关闭
询问开发人员并确保他们正在使用生产aps文件
确保在添加推送通知设置之后创建了配置文件。
通常我发现Option 1
是他们没有做的。
如果选项1、2、3没问题,请从一端检查编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.