2016-10-15 23 views
1

iOS 10のデフォルトのアプリ内通知を表示するようにOneSignalを設定しました。ただし、アプリ内通知を表示しない場合もあります。例えば。ユーザーが既に通知内の情報と同じページにいる場合。OneSignalを使用したマヌエルのアプリ内通知通知iOS10

OneSignalを使用して、デフォルトのiOS 10アプリ内通知を手動で表示するにはどうすればよいですか?

は、ここに私のコードです:あなたがtrueにアプリ内のアラートを設定する必要がappdelegateで

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]) 

答えて

0

。 p.s. DLogはデバッグモードでログインするためだけに使用され、無視することができます。デリゲートで

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 
} 

、あなたは、個々のオプションを設定することができ、その後、あなたは以下に示すようにcompletionHandler(options)を呼び出す必要があります:[OneSignal 2.2.0](https://github.com/のよう

// ========================================================================= 
// 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

OneSignal/OneSignal-iOS-SDK/releases/tag/2.2.0)では、 'OSUserNotificationCenterDelegate'を使用する必要はありません。代わりに、通常のように 'UNUserNotificationCenterDelegate'を直接設定する必要があります – jkasten

関連する問題