它曾经像魅力一样工作,从证书到天蓝色的后端,一切都已经完成。
但是从几天(不到一周)开始,我就不再收到推送通知了。
工作流程在设备上如下:
但是当我把它发送到azure时,我收到一个错误,详细的URL请求有错误:
URLRequest failed:
2017-03-15 18:27:41.174 Messenger[390:78044] URL:https://XXXX.servicebus.windows.net/messenger-dev/Registrations/XXXXXX-XXXXXX-1?api-version=2013-04
2017-03-15 18:27:41.175 Messenger[390:78044] Headers:{
Authorization = "SharedAccessSignature sr=http%3a%2f%2fYYYYYYY.servicebus.windows.net%2fXXXXXXXXX%3fapi-version%3d2013-04&sig=XXXXX&se=XXXXX&skn=DefaultListenSharedAccessSignature";
"Content-Type" = "application/xml";
"User-Agent" = "NOTIFICATIONHUBS/2013-04(api-origin=IosSdk; os=iPhone OS; os_version=9.2.1;)";
}
2017-03-15 18:27:49.897 Messenger[390:78044] ERROR : URLRequest failed for <NSMutableURLRequest: 0x12895e530> { URL: https://YYYYY.servicebus.windows.net/messenger-dev/Registrations/XXXXX?api-version=2013-04 } with status code: bad request
我试图通过邮递员发送这个,我得到了一个404 ...(如果我等了很长,生成的令牌已过期,则为401)。
修改
这是我的代码
@interface PushManager : NSObject {
SBNotificationHub *hub;
}
+ (PushManager *) sharedInstance;
@implementation PushManager
+ (PushManager *) sharedInstance {
static PushManager * instance = nil;
static dispatch_once_t token;
dispatch_once(&token, ^{
instance = [[self alloc] init];
});
return instance;
}
- (id) init {
if(self = [super init]) {
hub = [[SBNotificationHub alloc] initWithConnectionString:AZURE_CONNECTION_STRING
notificationHubPath:AZURE_NOTIFICATION_PATH];
}
return self;
}
- (void) enablePushNotificationForTopics:(NSSet<NSString *> *)topicsToEnable
addUserId:(BOOL)doAddUser
success:(PushManagerSuccessBlock) successBlock
error:(PushManagerErrorBlock) errorBlock {
if ([PushManager isApplicationEnableForPushNotification])
{
NSMutableSet<NSString *> *topicsToEnable = [NSMutableSet setWithSet:topicsToEnable];
[hub registerNativeWithDeviceToken:[[MessengerUserDefault sharedInstance] getPushNotificationToken]
tags:topicsToEnable
completion:^(NSError* error) {
if (error == nil) {
[TopicDBManager enablePushNotificationOnServerForTopics:topicsToEnable];
[[DBClient sharedInstance] saveContext];
successBlock();
}
else
{
NSLog(@"ERROR : %@",[error localizedDescription]);
errorBlock(error);
}
}];