我们从UA转移到一个信号。我们从云代码中发送推送,如
var pushInfo = {
"app_id" : "xxxxxx",
"data": {
"objectId": objectId,
"placeId": placeId,
},
"included_segments": ["All Users"],
"contents": {"en": message}
};
var headers = {
"Content-Type": "application/json; charset=utf-8",
"Authorization": "Basic XXXXX"
};
var options = {
host: "onesignal.com",
port: 443,
path: "/api/v1/notifications",
method: "POST",
headers: headers,
};
var https = require('https');
var req = https.request(options, function(res) {
res.on('data', function(data) {
console.log("Response:");
console.log(JSON.parse(data));
});
});
req.on('error', function(e) {
console.log("ERROR:");
console.log(e);
});
req.write(JSON.stringify(pushInfo));
req.end();在我的代理里。我知道。
[OneSignal initWithLaunchOptions:launchOptions appId:@"XXXXX"];现在,更早的时候,当收到通知并且用户点击它时,它会调用
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler问:现在不打电话了。如何用OneSignal来处理它。问:我需要做些什么来处理无声的通知(没有可见的徽章/横幅等)
发布于 2016-11-16 05:58:50
我想你是在iOS10设备上测试/运行你的应用程序,
我查看了OneSignal SDK代码,我认为当在设备上检测到iOS10时,SDK会自动使用新的iOS10框架(在iOS10中添加)。
在本例中,您前面提到的AppDelegate方法没有被调用,而是调用了UNUserNotificationCenterDelegate中的方法,这些方法被SDK捕获以记录单击/视图。
要解决这个问题,创建一个实现OSUserNotificationCenterDelegate的新类,并使用[OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]将其实例提供给OneSignal
请注意,当无声推送通知(内容可用: 1)到达时,仍会调用application:didReceiveRemoteNotification:fetchCompletionHandler:,但如果使用UNUserNotificationCenterDelegate,则不会调用它。
另外,在iOS 10.0.X上存在一个问题,在这里调用application:didReceiveRemoteNotification而不是application:didReceiveRemoteNotification:fetchCompletionHandler: --请参阅:https://forums.developer.apple.com/thread/54332,但我怀疑您是否会这样做。
发布于 2018-07-31 07:39:40
单信号通知集成
使用下面的代码块来处理PushNotification消息内容
将下面的代码放在AppDelegate的ApplicationDidFinishLaunch Options方法中
let notificationReceivedBlock: OSHandleNotificationReceivedBlock = { notification in
print("Received Notification: \(notification!.payload.notificationID)")
}
let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
// This block gets called when the user reacts to a notification received
let payload: OSNotificationPayload = result!.notification.payload
var fullMessage = payload.body
print("Message = \(String(describing: fullMessage))")
if payload.additionalData != nil {
if payload.title != nil {
let messageTitle = payload.title
print("payload.category \(payload.category)")
print("payload.subtitle \(payload.subtitle)")
print("Message Title = \(messageTitle!)")
}
let additionalData = payload.additionalData
if additionalData?["actionSelected"] != nil {
fullMessage = fullMessage! + "\nPressed ButtonID: \(String(describing: additionalData!["actionSelected"]))"
}
}
}
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInAppLaunchURL: true]
OneSignal.initWithLaunchOptions(launchOptions,
appId: "Your App Id",
handleNotificationReceived: notificationReceivedBlock,
handleNotificationAction: notificationOpenedBlock,
settings: onesignalInitSettings)
**Use following block of code To Receive OneSingnal Notification Content**
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;
// Recommend moving the below line to prompt for push after informing the user about
// how your app will use them.
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})发布于 2016-11-15 03:28:13
application:didReceiveRemoteNotification:fetchCompletionHandler:是背景静默content-available通知的正确选择器。确保您使用的是最新2.2.2 OneSignal SDK,因为有一些修复来维护与旧的AppDelegate选择器的兼容性。
您可能需要考虑使用UNNotificationServiceExtension和mutable-content一起使用iOS 10设备,因为这在应用程序被刷掉后仍然有效。
https://stackoverflow.com/questions/40600138
复制相似问题