2017-01-12 3 views
1

Я узнал, что настройки push-уведомлений были изменены в iOS10. Я выполнил необходимые шаги и развернул приложение через Xcode, затем протестировал и обработал push-уведомление. Затем я развернул его на TestFlight и попросил моего друга проверить его, но он не работает.Push Notification не работает на iOS 10 через TestFlight

Интересно, чего мне не хватает в моей следующей реализации. Мне кажется, что что-то связано с проблемой развития или производства, но я не знаю, что я делаю неправильно или что-то не хватает?

Я использовал следующую команду для генерации файла pem.

openssl x509 -inform der -in aps_production.cer -out certificate.pem 
openssl pkcs12 -nocerts -in Certificates.p12 -out p12Certificates.pem 
cat certificate.pem p12Certificates.pem > apns_cert.pem 

В моей apns.php, я звоню

// Открыть соединение с сервером APNS

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, 
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

Я добавил следующее в Info.plist

<key>aps-environment</key> 
<string>production</string> 

Возможности -> Push N otification установить его в ON

AppDelegate.h

#import <UIKit/UIKit.h> 
#import <UserNotifications/UserNotifications.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> 

@property (strong, nonatomic) UIWindow *window; 

AppDelegate.m

#define SYSTEM_VERSION_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
#ifdef __IPHONE_8_0 
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert                        | UIUserNotificationTypeBadge                        | UIUserNotificationTypeSound) categories:nil]; 
     [application registerUserNotificationSettings:settings]; 
#endif 
    } else { 
     UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
     [application registerForRemoteNotificationTypes:myTypes]; 
    } 

    if(SYSTEM_VERSION_EQUAL_TO(@"10.0")){ 
     UNUserNotificationCenter *notifiCenter = [UNUserNotificationCenter currentNotificationCenter]; 
     notifiCenter.delegate = self; 
     [notifiCenter requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ 
      if(!error){ 
       [[UIApplication sharedApplication] registerForRemoteNotifications]; 
      } 
     }]; 
    } 
    return YES; 

} 

#ifdef __IPHONE_8_0 
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 
{ 
    //register to receive notifications 
    [application registerForRemoteNotifications]; 
} 

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler 
{ 
    //handle the actions 
    if ([identifier isEqualToString:@"declineAction"]){ 
    } 
    else if ([identifier isEqualToString:@"answerAction"]){ 
    } 
} 
#endif 

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken 
{ 
    NSLog(@"My token is: %@", deviceToken); 
    NSData *someData = deviceToken; 
    NSString *someDataHexadecimalString = [someData hexadecimalString]; 
    NSLog(@"My token is: %@", someDataHexadecimalString); 

    [[NSUserDefaults standardUserDefaults] setObject:someDataHexadecimalString forKey:@"apnsToken"]; //save token to resend it if request fails 
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"apnsTokenSentSuccessfully"]; // set flag for request status 
} 

//foreground app. 
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ 
    NSLog(@"User Info : %@",notification.request.content.userInfo); 
    completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); 
} 

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ 
    NSLog(@"User Info : %@",response.notification.request.content.userInfo); 
    completionHandler(); 
} 

@end 
+1

Почему в вашей команде OpenSSL вы имеете в виду aps_development.cer но ваш жерех-среда производства? –

+1

@ MikeTaverne, я исправил. Пожалуйста, проигнорируйте это. – hotspring

ответ

1

1: сделать .pem файл живого сертификата APNS.

openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts 

2: сделать профиль обеспечения в режиме Ad Hoc затем Загрузить на testFlight

+1

Профиль профилирования в режиме AdHoc? – hotspring

+0

, когда вы создадите профиль распределения ресурсов, будет выбран вариант Ad Hoc, который будет проверять ваше нажатие в режиме реального времени. –

+0

Я хочу протестировать push-уведомление, чтобы приложение было в Apple Store. – hotspring

Смежные вопросы