Pau*_*aul 25 objective-c apple-push-notifications ios
我按照这个线程,但didRegisterForRemoteNotificationsWithDeviceToken仍未调用该方法:
文件说:
在调用UIApplication对象的registerForRemoteNotifications方法后,应用程序在设备注册成功完成时调用此方法
didRegisterUser看起来很好,但不是did register notif.
这是我在AppDelegate中的代码(应用程序版本是8.1):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register notif
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
return YES;
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
NSLog(@"didRegisterUser");
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"error here : %@", error);//not called
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/*
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
*/
NSLog(@"did register notif");//not called
}
Run Code Online (Sandbox Code Playgroud)
我还在info.plist中有后台模式 - >远程通知.
Kun*_*pta 28
长挖后,我发现,在2016年7月19日,由于在苹果结束一些错误或更新用的didRegisterForRemoteNotificationsWithDeviceToken方法不会被调用,即使像互联网连接,设备和使用的方法的每个条件都堪称完美.
请参阅此链接以进行确认https://forums.developer.apple.com/thread/52224
要验证,请查看您的其他应用.我浪费了几个小时,但希望它有所帮助.谢谢.
EI *_*2.0 24
2016年7月19日: -
根据Apple Developer表单,有一个关于Sandbox APNSdown 的问题...所以苹果方面可能存在问题,这就是为什么代表喜欢application:didRegisterForRemoteNotificationsWithDeviceToken:和application:didFailToRegisterForRemoteNotificationsWithError:不调用..
要查看APNS Sandbox 此链接的当前状态...现在根据状态APNS Sandbox工作正常且正常...所以可能是苹果方面还有其他一些错误
所以,如果您的方法完美且证书有效,请不要担心.这只是Apple方面的一个问题..一旦问题解决,你的方法就能很好地工作(如果你身边的一切都很好).
请注意,生产工作正常..所以问题仅涉及Sandbox APNS.
Bal*_*ali 19
对于IOS 13,
在didRegisterForRemoteNotificationsWithDeviceToken完全不被触发,当我连接到我的WiFi网络。我尝试了很多来解决这个问题,但不能。最后我将我的网络从 wifi 更改为蜂窝数据 & 突然它又开始工作了。我什至改回旧的 wifi 网络,它没有问题。
此外,如果您在 MAC 中使用 Internet 连接来使用 USB 进行共享。将其关闭并使用普通 wifi 或移动数据连接您的 iPhone。
Sve*_*ker 18
你的代码似乎是正确的.作为一个小改进,您可以编写didRegisterUserNotificationSettings方法,如下所示:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
if (notificationSettings.types != UIUserNotificationTypeNone) {
NSLog(@"didRegisterUser");
[application registerForRemoteNotifications];
}
}
Run Code Online (Sandbox Code Playgroud)
可能存在导致APN注册失败的配置问题.
确保您的Provisioning Profile包含aps-environment条目
确保您的Provisioning Profile中设置了唯一的App Identifier(不带任何"*"的字符串).您还应该在Info.plist中将此确切标识符用作"Bundle identifier"
也许您在初始安装后拒绝了推送功能 - 在这种情况下,您将永远不会再看到应用内推送警报,并且必须再次在设置应用中启用推送功能.
尝试其他设备.
Hom*_*ang 13
我遇到了这个问题,最后在Apple Developer网站上找到了这个问题并解决了这个问题:
iOS注意在"注册远程通知:
iOS注意:如果蜂窝或Wi-Fi连接不可用,则应用程序:didRegisterForRemoteNotificationsWithDeviceToken:方法和应用程序:didFailToRegisterForRemoteNotificationsWithError:方法都不会被调用.对于Wi-Fi连接,当设备无法通过端口5223与APN连接时,有时会发生这种情况.如果发生这种情况,用户可以移动到另一个未阻止此端口的Wi-Fi网络,或者在iPhone或iPad上等待直到蜂窝数据服务可用.在任何一种情况下,设备都应该能够建立连接,然后调用其中一个委托方法.
我的iPhone只与Wifi连接,重新启动iPhone并重新连接到WiFi AP解决了这个问题.
小智 10
好的,伙计们,我刚刚花了 11 个小时来调试这个东西,所以希望这个答案会对某人有所帮助。
如果您在类似线程中正确设置了所有内容并集成了 Google Firebase 分析,并且didRegisterForRemoteNotificationsWithDeviceToken 方法仍未被调用,这可能是因为它默认在 Google Firebase 中混合。出于某种奇怪的原因,FIR 在将您的令牌发送给 Google 后不会返回原始方法。修复它设置
FirebaseAppDelegateProxyEnabled to NO (BOOL)
Run Code Online (Sandbox Code Playgroud)
在您的 Info.plist 中。
XCode 8.3.1以后
在尝试了所有上述选项后,如果仍未调用委托方法,请确保在项目中,
under 'Capabilities', (next to General),
- Push Notifications option is turned ON`
- and under Background Modes, Remote Notifications is turned ON
Run Code Online (Sandbox Code Playgroud)
鄙视我!!O忘记了最基本的步骤:
在遵循所有证书流程说明之后:https : //www.pluralsight.com/guides/swift/creating-ios-rich-push-notifications
发送推送通知的工具是:https : //github.com/noodlewerk/NWPusher
愿原力与你同在!
对我来说,它是在模拟器上运行应用程序。没有为模拟器生成推送令牌,所以我输入didFailToRegisterForRemoteNotificationsWithError而不是didRegisterForRemoteNotificationsWithDeviceToken
| 归档时间: |
|
| 查看次数: |
45836 次 |
| 最近记录: |