2016-09-13 92 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