Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 10的推送通知问题_Ios_Push Notification_Ios10 - Fatal编程技术网

iOS 10的推送通知问题

iOS 10的推送通知问题,ios,push-notification,ios10,Ios,Push Notification,Ios10,我开发了一个应用程序,实现了推送通知。目前它在苹果专卖店直播。iOS 9之前的推送工作正常,但iOS 10之后就不工作了 代码有什么问题?对于使用xCode 8 GM的iOS 10 我已通过使用适用于iOS 10的xCode 8 GM的以下步骤解决了我的问题: 1) 在目标中的“功能”下,启用推送通知以添加推送通知权限 2) 在应用程序中实现UserNotifications.framework。在AppDelegate中导入UserNotifications.framework #import

我开发了一个应用程序,实现了推送通知。目前它在苹果专卖店直播。iOS 9之前的推送工作正常,但iOS 10之后就不工作了


代码有什么问题?

对于使用xCode 8 GM的iOS 10

我已通过使用适用于iOS 10的xCode 8 GM的以下步骤解决了我的问题:

1) 在目标中的“功能”下,启用推送通知以添加推送通知权限

2) 在应用程序中实现UserNotifications.framework。在AppDelegate中导入UserNotifications.framework

#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder   <UIApplicationDelegate,UNUserNotificationCenterDelegate>

@end
4) 现在,最后实现这两个委托方法

//===============适用于iOS 10=============

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{

    //Called when a notification is delivered to a foreground app. 

    NSLog(@"Userinfo %@",notification.request.content.userInfo);

    completionHandler(UNNotificationPresentationOptionAlert);
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{

   //Called to let your app know which action was selected by the user for a given notification.

   NSLog(@"Userinfo %@",response.notification.request.content.userInfo);

}
请保留您在iOS 9中使用的代码,
仅添加代码行以支持使用UserNotifications.framework的iOS 10推送通知。

在iOS 10之前,一切正常,在我的情况下,只有功能设置导致此问题

推送通知必须打开它


swift 3版本的@Ashish Shah代码是:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

//notifications
        if #available(iOS 10.0, *) {
            let center  = UNUserNotificationCenter.current()
            center.delegate = self
            center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
                if error == nil{
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
        } else {
            // Fallback on earlier versions
        }

        return true
    }
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

    }

我对iOS 10静默推送通知有问题。在iOS9和更早的版本中,发送包含额外数据字段但数据中有空
aps
属性的推送通知可以正常工作。但在iOS10中,带有空
aps
属性的推送通知根本不会命中DidReceiveMemoteNotification应用程序委托方法,这意味着我的所有静默推送通知(我们仅在应用程序打开时在内部使用以触发操作的通知)在iOS10中停止工作


通过在推送通知的
aps
部分添加至少一个属性,我可以在不向我的应用程序推送更新的情况下修复此问题,在我的情况下,我刚刚添加了
badge:0
,我的静默推送通知在iOS 10中再次开始工作。我希望这对其他人有帮助

在iOS上,应用程序通过调用
注册表通知设置:
策略获取推送警告的授权

应用程序调用
UIApplication
(iOS)的
registerforremotentifications:
技术或
NSApplication
(OS X)的策略
registerforremotentificationtypes:

应用程序执行
uiapplicationelegate
(iOS)或
nsapplicationelegate
(OSX)的
applicationderforremotentificationswithDeviceToken:
技术,以获得推送优惠产生的同类小工具令牌



应用程序执行
应用程序:didFailToRegisterforRemoteNotifications,错误为:
UIApplicationDelegate
(iOS)或
NSApplicationDelegate
(OSX)的
技术,如果注册失败,就会出错。

在测试时,不要忘记,您必须使用
沙盒
地址才能使通知生效。

“代码有什么问题?”-什么代码?使推送在iOS9上工作的代码显然是Hi Ashish,谢谢。这是一个很好的教程。但我想知道苹果公司必须明确提到这一点,对吗?他们有任何官方文件说明这一点吗?我也这么做了,但在应用程序终止时无法收到通知willPresentNotification==在应用程序处于前台且推送时调用,它可以用于配置显示或不显示incomed push-didReceiveNotificationResponse==从notification Centre打开通知时调用Hi@Ashish,我已经实现了上述框架和代码,但ios 10没有收到通知我不知道为什么请帮助我。为什么不检查是否已授予?在(prograted==NO)的情况下,回调将为错误发送nil。这意味着用户未注册。我通过单击推送通知部分的“修复我”按钮修复了它。问题是缺少按钮通知的权利每个人都喜欢一个答案,你只需点击一个按钮:D@Honey你能告诉我当应用程序在后台并收到用户通知时执行哪种方法吗?@ArgaPK see aps={badge=7;“content available”=1;priority=5;};我也有同样的问题。它帮助了我@jakedunc,谢谢你分享这个。同样的问题。似乎iOS 10对允许通过的内容更为严格。请注意,使用
优先级
5可能会导致推送根本不显示,如文档中所示:@杰克·邓克。aps属性来自服务器端,或者我们可以使用它。欢迎使用堆栈溢出!请注意。我已经编辑掉了你网站的链接。允许在用户页面上链接自己的站点。但是,在您获得最低分数之前,搜索引擎不会为其编制索引,以防止滥用。您能解释一下吗?在我的案例中,当从ios 9更新到10时,我的应用程序服务器将通知发送到我处于开发阶段的生产服务器,因此,将其改回开发沙箱解决方案解决了这个问题
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

//notifications
        if #available(iOS 10.0, *) {
            let center  = UNUserNotificationCenter.current()
            center.delegate = self
            center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
                if error == nil{
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
        } else {
            // Fallback on earlier versions
        }

        return true
    }
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

    }