App42:ios 设备上没有推送通知
App42: push notifications don’t come on ios device
上下文:
我正在尝试将我的 cocos2d-x(v.3.8.1) 应用程序从 Parse 迁移到 App42。一切都很好,除了推送通知。
我的工作:
我遵循这个 guide:
-使用.p12->.pem->.p12
转换
制作App42兼容的.p12证书
- 将此证书上传到 App42,它们在服务器上以绿色突出显示
- 为 Cocos2d-x
下载并安装最新的 App42 SDK ver.2.1
- 在 Appcontroller.mm
中注册推送通知:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
…
// Register for Push Notitications
App42API::Initialize(APP42_KEY, APP42_SECRET);
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
…
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString * deviceTokenString = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
app42->saveDeviceToken([deviceTokenString UTF8String]); // app42 is my singleton class for App42 methods
}
-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
-在我的单例中将 App42 与 APNS 绑定 App42Methods
:
void App42Methods::saveDeviceToken(string _deviceToken)
{
int tag = TAG_DEVICE_TOKEN;
deviceToken = _deviceToken;
string userName = deviceToken.substr(0, 25);
PushNotificationService::Initialize(APP42_KEY, APP42_SECRET);
DeviceType deviceType = APP42_IOS;
PushNotificationService* pushNotificationService = PushNotificationService::getInstance();
pushNotificationService->RegisterDeviceToken(_deviceToken.c_str(), userName.c_str(), deviceType, app42callback(App42Methods::onPushRequestCompleted, this));
}
void App42Methods::onPushRequestCompleted(void *response)
{
App42PushNotificationResponse *pushResponse = (App42PushNotificationResponse*)response;
if (pushResponse->isSuccess)
{
log("Push notification service registered!");
}
else
{
printf("\nerrordetails:%s",pushResponse->errorDetails.c_str());
printf("\nerrorMessage:%s",pushResponse->errorMessage.c_str());
printf("\nappErrorCode:%d",pushResponse->appErrorCode);
printf("\nhttpErrorCode:%d",pushResponse->httpErrorCode);
}
}
所以,注册过程没问题。我在日志中得到 "Push notification service registered!"
,在服务器上 App42 Cloud API -> Unified Notifications -> Push Users
我可以看到创建的用户具有正确的设备令牌。
我select在服务器上推送通知给他,这个通知显示为已发送。但是我可以在我的设备上收到任何通知。
我正在尝试做:
我尝试将 Push Notification Plugin 用于 Cocos2d-x,结果相同。
我还使用了 APN 测试器,它记录了 «Failure performing handshake, error code -9806»
.
我也可以为 iOS 尝试 App42 SDK,但这会导致重写整个 App42Methods class。我想避免这种情况。
推送通知在 Parse.com.
上运行良好
请告诉我我做错了什么? App42好像连不上APNS,不知道为什么。
任何帮助将不胜感激。
握手问题一般是由于p12文件的问题。您可以参考 this post for the same. I will suggest you to recreate your .p12 file following the same tutorial and try. If you still face the issue then you can write at support@shephertz.com or App42 community forum 以快速解决问题。
上下文:
我正在尝试将我的 cocos2d-x(v.3.8.1) 应用程序从 Parse 迁移到 App42。一切都很好,除了推送通知。
我的工作:
我遵循这个 guide:
-使用.p12->.pem->.p12
转换
制作App42兼容的.p12证书
- 将此证书上传到 App42,它们在服务器上以绿色突出显示
- 为 Cocos2d-x
下载并安装最新的 App42 SDK ver.2.1
- 在 Appcontroller.mm
中注册推送通知:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
…
// Register for Push Notitications
App42API::Initialize(APP42_KEY, APP42_SECRET);
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
…
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString * deviceTokenString = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
app42->saveDeviceToken([deviceTokenString UTF8String]); // app42 is my singleton class for App42 methods
}
-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
-在我的单例中将 App42 与 APNS 绑定 App42Methods
:
void App42Methods::saveDeviceToken(string _deviceToken)
{
int tag = TAG_DEVICE_TOKEN;
deviceToken = _deviceToken;
string userName = deviceToken.substr(0, 25);
PushNotificationService::Initialize(APP42_KEY, APP42_SECRET);
DeviceType deviceType = APP42_IOS;
PushNotificationService* pushNotificationService = PushNotificationService::getInstance();
pushNotificationService->RegisterDeviceToken(_deviceToken.c_str(), userName.c_str(), deviceType, app42callback(App42Methods::onPushRequestCompleted, this));
}
void App42Methods::onPushRequestCompleted(void *response)
{
App42PushNotificationResponse *pushResponse = (App42PushNotificationResponse*)response;
if (pushResponse->isSuccess)
{
log("Push notification service registered!");
}
else
{
printf("\nerrordetails:%s",pushResponse->errorDetails.c_str());
printf("\nerrorMessage:%s",pushResponse->errorMessage.c_str());
printf("\nappErrorCode:%d",pushResponse->appErrorCode);
printf("\nhttpErrorCode:%d",pushResponse->httpErrorCode);
}
}
所以,注册过程没问题。我在日志中得到 "Push notification service registered!"
,在服务器上 App42 Cloud API -> Unified Notifications -> Push Users
我可以看到创建的用户具有正确的设备令牌。
我select在服务器上推送通知给他,这个通知显示为已发送。但是我可以在我的设备上收到任何通知。
我正在尝试做:
我尝试将 Push Notification Plugin 用于 Cocos2d-x,结果相同。
我还使用了 APN 测试器,它记录了 «Failure performing handshake, error code -9806»
.
我也可以为 iOS 尝试 App42 SDK,但这会导致重写整个 App42Methods class。我想避免这种情况。
推送通知在 Parse.com.
请告诉我我做错了什么? App42好像连不上APNS,不知道为什么。
任何帮助将不胜感激。
握手问题一般是由于p12文件的问题。您可以参考 this post for the same. I will suggest you to recreate your .p12 file following the same tutorial and try. If you still face the issue then you can write at support@shephertz.com or App42 community forum 以快速解决问题。