我创建了两个证书,并且门户中的 APP 为开发和生产启用了 APNS。
在开发中它工作正常,但在生产中,当有人下载应用程序并登录我的服务器时,会使用代表No Push Notifications的NAPN进行更新。
如果用户禁用它们,这是代码部分,但我已经检查了多个用户并且它们已完全启用但由于某种原因它就像它被困在开发 APNS 证书或其他东西上,也没有提示用户在他们首次下载和启动应用程序时启用推送通知。
我不知道我是否需要向苹果提出这个问题,但如果有人可以,请提供有关如何使其工作的建议,我们将不胜感激。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//Clear notifications upon launching
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
//Register with APN
if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] != 0)
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}else
{
URLSingleton *registrar = [URLSingleton sharedInstance];
[registrar setDevToken:@"NAPN"];
//Register APN with iShame Service
URLSingleton *urls = [URLSingleton sharedInstance];
NSString *authString = [NSString stringWithFormat:@"{\"user\":\"%@\",\"token\":\"%@\"}", [[NSUserDefaults standardUserDefaults] valueForKey:@"session_token"], [registrar getDevToken]];
NSData *authData = [authString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urls.updateAuth]];
[url setHTTPMethod:@"POST"];
[url setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[url setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[url setValue:@"json" forHTTPHeaderField:@"Data-Type"];
[url setValue:[NSString stringWithFormat:@"%d", [authData length]] forHTTPHeaderField:@"Content-Length"];
[url setHTTPBody:authData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[connection start];
}
return YES;
}