2016-09-13 60 views
0

测试我的设备上使用OneSignal服务发送推送通知我处理它的AppDelegate这样:通知警告禁止迅速

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 

     OneSignal.initWithLaunchOptions(launchOptions, appId: “[app ID]”)//this method I register device on apple server 

     return true 
    } 

func application(application: UIApplication, 
         didReceiveRemoteNotification userInfo: [NSObject : AnyObject], 
                fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void){ 

     print(“ARRIVED") 
     handleNotificationContent()// it’s not important for my question 
} 

我的问题是,当我收到通知,该应用程序是在前景中,警报自动显示,我不想显示它。 我该如何解决这个问题?

回答

0

您需要将kOSSettingsKeyInFocusDisplayOption设置为None,initWithLaunchOptions,以禁用自动显示inapp警报。

OneSignal Api Reference

+0

:悬而未决的标识“无”的使用。有什么建议么?当我使用false时,错误消失了? –

+0

@PeterdeVries这就是你需要的:'OSNotificationDisplayType.none.rawValue' – oyalhi

+0

@oyalhi。这工作,非常感谢。 –

2

此代码适用于我。

当我使用上面的我得到这适用于雨燕2.2和Xcode中7.3.1

//Initialize One Signal using this code 

OneSignal.initWithLaunchOptions(launchOptions, appId: oneSignalId, handleNotificationReceived: { (notification) in 

    //Put your business logic here like adding an alert controller or posting an NSNotification. 

}, handleNotificationAction: { (nil) in 

    // This block gets called when the user reacts to a notification received 

}, settings: [kOSSettingsKeyAutoPrompt : false, kOSSettingsKeyInAppAlerts: false]) 

    //set kOSSettingsKeyAutoPrompt to false 
+1

不错的Jas! :) – Woppi

+0

嗨,我可以问一下。 oneignal还支持swift 2.2吗?如果我在他们的文档https://documentation.onesignal.com/docs/ios-sdk-setup中安装它的pod,我仍然可以下载支持swift 2.2的pod吗?或自动它的更新版本为SWIFT 3?只是问ty – Reginald