ios 在 iPhone 中没有收到任何推送通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16140055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:16:57  来源:igfitidea点击:

Not receiving any push notification in iPhone

iosiphoneobjective-cpush-notificationapple-push-notifications

提问by Idiot

I have made a sample PushTest app for Push Notification using this tutorial.

我使用本教程制作了一个用于推送通知的示例 PushTest 应用程序。

And using above tutorial I got the message that 'PushTest' would like to send you Push Notification (exactly once) and after that I delete the app from iPhone, restart the iPhone but unable to get the same message again.

使用上面的教程,我收到了“PushTest”想要向您发送推送通知(恰好一次)的消息,之后我从 iPhone 中删除了该应用程序,重新启动 iPhone,但无法再次收到相同的消息。

I have run the script sample.php (updating the changes suggested) and got the message 'connected to APNS' & 'your message send'.

我已运行脚本 sample.php(更新建议的更改)并收到消息“已连接到 APNS”和“您的消息发送”。

But I didn't receive any single push notification.

但是我没有收到任何推送通知。

Please guide me where I am wrong?
Or what shod I try for push notification receive.

请指导我我错在哪里?
或者我尝试什么来接收推送通知。

回答by Divyam shukla

You will not receive Push only in 2 cases

仅在 2 种情况下您不会收到推送

1.) If your application is in foreground.

1.) 如果您的应用程序在前台。

2.) you device token is not valid for receiving the push notification please check both the condition if you still do not receive push please let me know. Thanks

2.) 您的设备令牌对于接收推送通知无效,请检查两个条件,如果您仍然没有收到推送,请告诉我。谢谢

回答by Saqib Saud

Make sure you are using push notification enabled provisioning profile. and then check if you are sending token to server.

确保您使用的是启用推送通知的配置文件。然后检查您是否正在向服务器发送令牌。

回答by Baby Groot

I have followed the same tutorial.

我遵循了相同的教程。

Make sure your app is listed in notification center, and it's alert type is anything but not none.

确保您的应用程序列在通知中心,并且它的警报类型是任何但不是没有。

You need to check your notification in 3 conditions,

您需要在 3 个条件下检查您的通知,

When your app is open, in background, and when closed.

当您的应用程序处于打开状态、后台状态和关闭状态时。

For that, you need to in check these methods

为此,您需要检查这些方法

// To Register your device token
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken


//If your app is not able to register
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{}


//Your app receives push notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

    UIApplicationState state = [application applicationState];

    // If your app is running
    if (state == UIApplicationStateActive)
    {

        //You need to customize your alert by yourself for this situation. For ex,
        NSString *cancelTitle = @"Close";
        NSString *showTitle = @"Get Photos";
        NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
                                                            message:message
                                                           delegate:self
                                                  cancelButtonTitle:cancelTitle
                                                  otherButtonTitles:showTitle, nil];
        [alertView show];
        [alertView release];

    }
    // If your app was in in active state
    else if (state == UIApplicationStateInactive)
    {
    }
}

回答by Fattie

BE AWARE OF THE BATTERY ISSUE, WHICH BLOCKS YOU FOR ONE DAY OR MORE

请注意电池问题,该问题会阻碍您一天或更长时间

Never, ever, ever, start testing pushes in development mode (tethered phone) unless the phone is FULLY CHARGED.

除非手机充满电,否则永远不要在开发模式(系留电话)下开始测试推送。

https://developer.apple.com/library/archive/technotes/tn2265/_index.html

https://developer.apple.com/library/archive/technotes/tn2265/_index.html

If your notification payload contains the content-available key, your app will receive the notification if iOS or OS X determines it is energy-efficient to do so. If the energy or data budget for the device has been exceeded, your app will not receive any more notifications with the content-available key until the budget has been reset. This occurs once a day and cannot be changed by user or developer action.

如果您的通知负载包含 content-available 密钥,并且 iOS 或 OS X 确定这样做是节能的,您的应用程序将收到通知。如果超过了设备的能源或数据预算,在重置预算之前,您的应用将不会再收到任何带有 content-available 密钥的通知。这每天发生一次,并且不能通过用户或开发人员的操作进行更改

In general, notifications (particularly when you are tethered) are incredibly flakey regarding battery state of the phone. (Also, some of the stuff mentioned in that article, which is very old, is plain wrong.) Basically you often JUST WILL NEVER GET notifications if your phones enter "don't get notifications because of battery" mode - and it can go on for days.

一般来说,关于手机电池状态的通知(特别是当你被束缚时)非常奇怪。(此外,那篇文章中提到的一些内容非常古老,完全是错误的。)基本上,如果您的手机进入“由于电池而无法收到通知”模式,您通常永远不会收到通知 - 它可以继续几天。

Notifications do (or did) prefer cellular WTF!!!

通知确实(或确实)更喜欢蜂窝 WTF !!!

On iOS, push notifications use the cellular data network whenever possible, even if the device is currently using Wi-Fi for other network activity such as web browsing or email. However, the push service will fall back to Wi-Fi if cellular data service isn't available.

在 iOS 上,推送通知会尽可能使用蜂窝数据网络,即使设备当前正在使用 Wi-Fi 进行其他网络活动,例如网页浏览或电子邮件。但是,如果蜂窝数据服务不可用,推送服务将回退到 Wi-Fi。

This has changed a lot with different iOS versions but it's a huge hassle.

这在不同的 iOS 版本中发生了很大变化,但这是一个巨大的麻烦。

>>>>> !!! CRITICAL TIP !!! <<<<<

>>>>> !!!关键提示!!!<<<<<

Don't forget that:

不要忘记:

  1. Build to a tethered phone. You will only get the "sandbox, development" push notifications. BUT THOSE BARELY WORK - THEY ARRIVE VERY LATE, DO NOT WORK IN SOME REGIONS, AND SO ON. THEY ARE SO FLAKEY THEY ARE USUALLY NOT WORTH TRYING.

  2. Increase build number, build normally for Test Flight, send to test flight, and then install from Test Flight. You will now get CORRECT, NORMAL APPLE PUSH NOTIFICATIONS.

  1. 构建到系留电话。您只会收到“沙盒、开发”推送通知。 但那些几乎没有工作 - 他们到的很晚,在某些地区不工作,等等。它们是如此脆弱,通常不值得尝试。

  2. 增加构建号,正常构建用于试飞,发送到试飞,然后从试飞安装。您现在将获得正确、正常的 Apple 推送通知

Very confusingly you !!DO!!get REALpush notifications on development Test Flight builds.

你很困惑!!做!! 获取有关开发测试飞行版本的真实推送通知。

That is to say - when you build to TestFlight you DO GETexactly the same "real"push notifications as for actual apps published on the app storeand used by your public users - real, true, APNS push notifications.

也就是说-当你建立到TestFlight你做得到完全一样的“真正的”推送通知作为发布在App Store上的应用程序的实际和你的公众用户使用的-真正的,真实的,APNS推送通知。

The incredibly confusingly-named "development, sandbox" push notifications are ONLYfor "tethered phone builds". (AND, to add confusion on confusion, the "development, sandbox" push notifications are very unreliable, so you never really know if they are working or not.)

令人难以置信的令人困惑的名称“开发,沙盒”推送通知适用于“系留电话构建”。(并且,为了增加混淆,“开发,沙箱”推送通知非常不可靠,因此您永远不会真正知道它们是否有效。)

Read more here! https://stackoverflow.com/a/60550859/294884

在这里阅读更多! https://stackoverflow.com/a/60550859/294884

回答by Yogi

Please check in your device's Settingsif notifications for the application are on and ensure that the type of the notification is not 'None' in Notification Center.

如果应用程序的通知处于开启状态,请检查您设备的设置,并确保通知中心中的通知类型不是“无” 。

回答by Nik Kov

Make sure, that you select right provision profile provision profile

确保您选择了正确的配置文件 配置文件

and that your app is minimized. If app's not minimized use

并且您的应用已最小化。如果应用程序没有最小化使用

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"info %@", userInfo);
}

Other useful informationabout issues.

有关问题的其他有用信息

For TESTING pushes you can use APN Tester Free. Attention:insert token WITH spaces.

对于 TESTING 推送,您可以使用APN Tester Free注意:插入带有空格的标记。

回答by Mantas Laurinavi?ius

I was not getting anything in:

我没有得到任何东西:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any])

But my compiler stopped on breakpoint in

但是我的编译器在断点处停止

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

回答by Manish Jain

I ran into a similar issue. Everything was done correctly in the code. I was running the app with a development profile and push notifications on the server (iOS) pointing to production. Make sure your provisioning profile matches the server setting(Sandbox vs. Production). You can also make sure your device is registering correctly.

我遇到了类似的问题。一切都在代码中正确完成。我正在使用开发配置文件运行应用程序,并在指向生产的服务器 (iOS) 上推送通知。确保您的配置文件与服务器设置(沙盒与生产)相匹配。您还可以确保您的设备正确注册。