3

我們從UA遷移到One Signal。我們就像OneSignal未調用didReceiveRemoteNotification

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(); 

發送從雲代碼推在我AppDelegate.m我做

[OneSignal initWithLaunchOptions:launchOptions appId:@"XXXXX"]; 

現在早些時候收到通知,用戶點擊它,它用來調用

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 

問:現在沒有被調用。我如何處理OneSignal。 問:我需要做什麼來處理無聲通知(無可見的徽章/橫幅等)

回答

3

我假設你正在測試/一iOS10設備上運行的應用程序,

我看着OneSignal SDK代碼,我覺得SDK會自動使用新UserNotifications框架(加入iOS10),當檢測到iOS10設備。

在這種情況下,上面提到的AppDelegate方法不會被調用,而是調用UNUserNotificationCenterDelegate中的方法,SDK中捕獲的方法用於記錄點擊/視圖。

要解決此問題,創建一個實現OSUserNotificationCenterDelegate一個新的類,並使用[OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]

請注意,當無聲推送通知(內容提供:1)application:didReceiveRemoteNotification:fetchCompletionHandler:仍稱以OneSignal提供它的實例來了,但是如果使用UNUserNotificationCenterDelegate,當用戶點擊通知時不會調用它。

此外,在iOS 10.0.X中出現了一個問題,其中application:didReceiveRemoteNotification被調用而不是application:didReceiveRemoteNotification:fetchCompletionHandler:請參閱:https://forums.developer.apple.com/thread/54332,但我懷疑這是否屬於您。

+0

謝謝。可能僅僅使用[OneSignal initWithLaunchOptions:launchOptions appId:@「XXXX」handleNotificationReceived:^(OSNotification * notification){}將是一個不錯的主意,它將始終跨越iOS8/9/10 – user1191140

相關問題