gpt4 book ai didi

ios - 推送通知无法通过 TestFlight 在 iOS 10 上运行

转载 作者:行者123 更新时间:2023-11-29 11:49:52 25 4
gpt4 key购买 nike

我了解到推送通知设置在 iOS10 中已更改。我已经完成了所需的步骤并通过 Xcode 部署了应用程序,然后进行了测试并且推送通知有效。然后部署到TestFlight上,让 friend 测试,还是不行。

我想知道我在接下来的实现中遗漏了什么。在我看来,某些事情与开发与生产问题有关,但我不知道我做错了什么或遗漏了什么?

我已经使用下面的命令来生成 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>

Capabilities --> Push Notification 将其设置为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:制作实时APNS证书的.pem文件。

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

2:在 Ad hoc 模式下制作配置文件,然后在 testFlight 上上传

关于ios - 推送通知无法通过 TestFlight 在 iOS 10 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41605967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com