我已经知道iOS10中的推送通知设置已经更改。我已经完成了所需的步骤并通过Xcode部署了应用程序,然后进行了测试并且推送通知有效。然后我将它部署在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>
功能 - &gt;推送通知将其设置为开启
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
答案 0 :(得分:1)
1:制作实时APNS证书的.pem文件。
openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts
2:在Ad hoc模式下进行配置文件,然后在testFlight上进行上传