2016-10-15 1 views
1

Ich habe das OneSignal so eingerichtet, dass iOS 10 Standard-In-App-Benachrichtigungen angezeigt werden. In einigen Fällen sollte die In-App-Benachrichtigung jedoch nicht angezeigt werden. Z.B. wenn sich der Benutzer bereits auf derselben Seite wie die Info in der Benachrichtigung befindet.Manuel In-App-Benachrichtigungsalarm mit OneSignal iOS10

Wie kann ich die standardmäßige In-App-Benachrichtigung für iOS 10 manuell mit OneSignal anzeigen?

Hier ist mein Code:

OneSignal.initWithLaunchOptions(launchOptions, appId: "your-app-id-here", handleNotificationReceived: ({ (notification) in 
     LGNotificationHandler.handleNotification(notification) 
    }), handleNotificationAction: ({ (result) in 
     LGNotificationHandler.handleNotificationAction(result: result) 
    }), settings: [ 
     kOSSettingsKeyAutoPrompt: false, 
     kOSSettingsKeyInAppAlerts: false, 
     kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayType.notification.rawValue]) 

Antwort

0

In AppDelegate, wo Sie die In-App-Benachrichtigungen auf true setzen müssen. p.s. DLog wird nur für die Anmeldung im Debug-Modus verwendet, kann ignoriert werden.

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

    // MARK: - OneSignal Notifications 
    OneSignal.initWithLaunchOptions(launchOptions, appId: "your-app-id-here", handleNotificationReceived: ({ (notification) in 
     DLog("handleNotificationReceived: \(notification)") 
    }), handleNotificationAction: ({ (result) in    
     DLog("handleNotificationAction: \(result)") 
     LGNotificationHandler.handleNotificationAction(result) 
    }), settings: [ 
     kOSSettingsKeyAutoPrompt: false, 
     kOSSettingsKeyInAppAlerts: true, 
     kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayType.none.rawValue 
    ]) 

    // You will get a warning here if you are using the latest OneSignal library, but can be safely ignored for the time being. 
    OneSignal.setNotificationCenterDelegate(self) 

    DLog("--- appDelegate end") 
    return true 
} 

In den Delegierten können Sie einzelne Optionen festlegen, dann müssen Sie completionHandler(options) nennen, wie unten dargestellt:

// ========================================================================= 
// MARK: - OSUserNotificationCenterDelegate 
extension AppDelegate: OSUserNotificationCenterDelegate { 
    func userNotificationCenter(_ center: Any!, willPresentNotification notification: Any!, withCompletionHandler completionHandler: ((UInt) -> Swift.Void)!) { 
     // set the options here 
     var options: UInt = 0 

     options |= UNNotificationPresentationOptions.badge.rawValue // if you want to show the badge number 
     options |= UNNotificationPresentationOptions.alert.rawValue // if you want to show alert dialog box 
     options |= UNNotificationPresentationOptions.sound.rawValue // if you want notification to play sound 

     // here we perform the notifications 
     completionHandler(options) 
    } 
} 
+0

Ab [OneSignal 2.2.0] (https://github.com/ OneSignal/OneSignal-iOS-SDK/releases/tag/2.2.0) Sie müssen nicht mehr "OSUserNotificationCenterDelegate" verwenden. Sie sollten stattdessen "UNUserNotificationCenterDelegate" direkt wie üblich setzen – jkasten