Post not yet marked as solved
My use case : i want the app to completely silence a given received alert push notification, based on information the app has locally (completely remove it, and never even display it. Not just change the sound or badge).
So far i found no way of doing that :
notification service extension doesn't let you remove the notification entirely, just change its content.
Using "background / content" notification type then creating the notification locally doesn't work, since "background" notification type is unreliable by design.
voip notifications are banned from being used as a general-purpose background notification mechanism since iOS13
Help would be greatly appreciated.
Post not yet marked as solved
We are entitled by Apple for critical alerts.
Our app is an alerting app which shall now be used to alert deaf persons.
We did not find the possibility to alert deaf persons, by choosing vibration instead of sound.
The accessibility options of iOS don't seem to provide an option to choose vibration instead of sound. It does vibrate for a very short amount of time, but it must vibrate for at least 10-20 seconds to be of any help.
Is there any possibility to vibrate upon receiving a critical alert notification for that amount of time? We're also using a notification service extension, but we're more interested in an official solution, than a "hack" solution.
Post not yet marked as solved
Upgraded ios 13.6 and changed bundle identifier and container name. Created CKDatabaseSubscription for both public and shared database and can see in cloudkit dashboard. Both didFinishLaunchingWithOptions and didRegisterForRemoteNotificationsWithDeviceToken get called in AppDelegate.
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: { granted, error in
guard granted else { return }
DispatchQueue.main.async {
application.registerForRemoteNotifications()
print("Registered for Remote notifications")
}
})
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
})
self.iCloudSubscribeToPrivateDB()
self.iCloudSubscribeToSharedDB()
}
In the project both background fetch and remote notifications are enabled. I make databases changes in cloudkit dashboard, but push notifications are not being sent. They were working now just stopped after I made the above changes. What could be wrong?
Post not yet marked as solved
Hello. After the ios14 update, there was a problem that the application I distributed did not request notification permission.
In ios 13.7 version, notification permission is normally requested, but the device that has updated ios 14 does not request notification permission.
When requestAuthorization outputs the error details to completionHandler, the following error is displayed.
===========================================
Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}
===========================================
If you know how to fix it, please let me know.
Have a nice day.
Post not yet marked as solved
I have an app that implements my own Packet Tunnel Provider, and to my knowledge everything I do is working as intended. However, I came across an issue with NEVPNStatusDidChange NotificationCentre observations when calling the following function multiple times:NETunnelProviderManager:loadAllFromPreferences(completionHandler:)
From the documentation:
You must call loadFromPreferences(completionHandler:): at least once before calling this method the first time after your app launches. As a result of this note, an early implementation I had took a very conservative approach; calling loadFromPreferences(completionHandler:): every time before operating on my NEPacketTunnelProvider. This was done by a helper function which was run as a precursor to any operation done to the manager, ensuring that the latest manager was being used every time. This looked something like:func myStartVPN() {
		loadHelper { (manager: NEPacketTunnelProvider, error: Error?) in
/* handle errors */
startVPN(withManager: manager)
}
}
When using this approach, I noticed that observers that look for NEVPNStatusDidChange events got triggered multiple times for these events, with the number of times it being triggered machine the number of times I called loadAllFromPreferences(). Chronologically speaking I was experiencing something along the lines of Appendix 1.
As a result of this issue, my production equivalent of loadHelper(), above, only calls load once the first time a manager is requied, and then subsequent operations on the manager use a cached value - a bit like a standard lazy field.
Obviously this is not a big issue as I have a working solution, however I haven't been able to work out what causes this behaviour - does anyone have any ideas? Could it be a general Swift/Objective C pitfall with KVO that I am not aware of?
Could it be some sort of issue with NetworkExtension/my approach? (I'm thinking some references might not be being cleaned up every time I load?)
Appendix 1
Previously set up NEPacketTunnelProvider*
loadAllFromPreferences() followed by saveManager()
Recieve NEVPNStatusDidChange - Disconnected
loadAllFromPreferences() followed by startVPNTunnel()
Recieve NEVPNStatusDidChange - Connecting x2
Recieve NEVPNStatusDidChange - Connected x2
loadAllFromPreferences() followed by stopVPNTunnel()
Recieve NEVPNStatusDidChange - Disconnecting x3
Recieve NEVPNStatusDidChange - Disconnected x3
loadAllFromPreferences() followed by startVPNTunnel()
Recieve NEVPNStatusDidChange - Connecting x4
Recieve NEVPNStatusDidChange - Connected x4
loadAllFromPreferences() followed by stopVPNTunnel()
Recieve NEVPNStatusDidChange - Disconnecting x5
Recieve NEVPNStatusDidChange - Disconnected x5
Post not yet marked as solved
Hi, everyone!
I'm trying to do push notification for apple wallet pass via PHP. My code (in 2 variants) is below. According to guidelines - https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/Updating.html I should get the response in json format, but i don't. Anyway in the server logs I see the response 200. Any notification doesn't appear on the device.
I also tried to push notification via command line tools, but also faced problems - the guideline - https://developer.apple.com/documentation/usernotifications/sending_push_notifications_using_command-line_tools give info only about push notification for your own app, not for the Wallet.
I will be very grateful for any responses.
№1
				$apnsServer = 'tcp://api.push.apple.com:443/3/device/';
		
				$privateKeyPassword = '<password>';
				$message = 'test';
				$deviceToken =
				'<token>';
			
				$pushCertAndKeyPemFile = 'my.pem';
				$stream = stream_context_create();
				stream_context_set_option($stream,
				'ssl',
				'passphrase',
				$privateKeyPassword);
				stream_context_set_option($stream,
				'ssl',
				'local_cert',
				$pushCertAndKeyPemFile);
				$connectionTimeout = 20;
				$connectionType = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
				$connection = stream_socket_client($apnsServer,
				$errorNumber,
				$errorString,
				$connectionTimeout,
				$connectionType,
				$stream);
				if (!$connection){
				echo "Failed to connect to the APNS server. Error no = $errorNumber<br/>";
				exit;
				} else {
				echo "Successfully connected to the APNS. Processing...</br>";
				}
				$messageBody['aps'] = array('alert' => $message,
				'sound' => 'default',
				'badge' => 2,
				);
				$payload = json_encode($messageBody);
				$notification = chr(0) .
				pack('n', 32) .
				pack('H*', $deviceToken) .
				pack('n', strlen($payload)) .
				$payload;
				$wroteSuccessfully = fwrite($connection, $notification, strlen($notification));
				$apple_error_response = fread($connection, 6);
				if (!$wroteSuccessfully){
				echo "Could not send the message<br/>";
				}
				else {
				echo "Successfully sent the message<br/>";
				}
				fclose($connection);
?>
№2
$apnsCert = 'my.pem';
$push_token = '<token>';
$passIdentify = '<pass identify>';
$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1, 'sound' => 'default');
$output = json_encode($payload);
$msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($output)) . $output . pack('n', strlen($passIdentify)) . $passIdentify;
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client("api.push.apple.com:443/3/device/", $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if (!$apns)
exit ("APNS Connection Failed: $error $errorString" . PHP_EOL);
var_dump($apns);
if(fwrite($apns, $msg)) {
		echo "ok";
} else {
		echo "not ok ".error_reporting(E_ALL);
}
socket_close($apns);
fclose($apns);
Post not yet marked as solved
I recently updated to iOS 14.2 and ever since my phones iMessage has been glitching. I have the iPhone XR so it’s not that it’s a particularly old phone... however I no longer get notifications when I get iMessages. My phone also opens messages before I’ve seen them...
to explain, it’ll send a read receipt before I’ve actually seen the message, and thus, “reads the message” so I get no notification. It’s hard to explain but my contacts are being told I’ve read their message- when I haven’t. I’ve tried restarting my phone and it keeps happening. Anyone got any tips? Or is this an IOS glitch?
thanks!
Post not yet marked as solved
Hi Team,
I was trying to add NSE to my Project to show Rich messaging. Creation of the NSE target to the project - Successful.
Creation of additional provisioning profile in developer portal for NSE and mapped it in XCode - Successful
The APS payload contains the content-type: 1 and attachment url to download the media content - Successful.
When notification arrive the will present method gets called first - Successful.
The auto execution of Notification Service 'didReceive(_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping
(UNNotificationContent) - Void)' - failure.
6. Tried running the target instead of main app - failure
7. Tried attaching a debugger to get break point - failure
8. Debug and Console logs - failure
9. Additionally tried the below option from every developer suggestion but no luck.
o https://stackoverflow.com/questions/50853503/images-in-ios-push-notification
o https://stackoverflow.com/questions/51722109/unnotificationserviceextensions-didrecieve-not-called
o https://stackoverflow.com/questions/39663903/ios10-unnotificationserviceextension-not-called
o https://stackoverflow.com/questions/46463680/notificationserviceextension-not-called
o https://stackoverflow.com/questions/45483018/unnotificationserviceextension-not-working-on-iphone-5-ios-10
Could you please assist on the same to get it working as the notification service methods cannot be called explicitly and it needs to be triggered by OS.
A quick, faster response and resolution is much appreciated.
Post not yet marked as solved
I want to add a category to my push notification and I can't seem to get any success in my attempts. I tried StackOverflow, but nobody responded, so I'm trying here.
I thought it would be an issue with my Firebase Cloud Functions message payload, but it's not.
I have a function to set a category on my notification when interacted with:
func configureCategory() {
let viewAction = UNNotificationAction(identifier: "viewNewEvent", title: "View New Event", options: UNNotificationActionOptions.foreground)
let viewCategory = UNNotificationCategory(identifier: "newEventCategory", actions: [viewAction], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories(Set([viewCategory]))
}
I then call this right before application.registerForRemoteNotifications()
From, reading many articles, I thought this would work, but my notification just ends up with no actions when i receive it and interact with it.
I even decided to create a UNNotificationServiceExtension, and add the identifier in that, but that didn't work either.
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) - Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
bestAttemptContent.categoryIdentifier = "newEventCategory"
contentHandler(bestAttemptContent)
}
}
If anybody knows how to do this properly and sees I'm missing something or placing something in the wrong spot, please point it out and let me know, thanks.
Post not yet marked as solved
I have created a UNNotificationRequest with following code in a macOS app
let content = UNMutableNotificationContent()
content.title = "Welcome"
content.body = "body"
content.sound = UNNotificationSound.default
var dateComponent = DateComponents()
dateComponent.year = 2021
dateComponent.day = 24
dateComponent.hour = 12
dateComponent.minute = 27
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponent, repeats: true)
let request: UNNotificationRequest = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
}
I want the notification to trigger on 24th of every month in 2021.
When the notification is triggered, it generates repeated duplicate notifications every second. If I make the year attribute in datecomponents to nil, then it does not generate repeated duplicate notifications.
But I need to set the year attribute according to my requirement. I tried the same code in a sample iOS app. It does not generate duplicate notifications. It generates only in macOS app.
What is the solution for not generating repeated duplicate notifications if I set the year attribute in datecomponents?
Post not yet marked as solved
Hello Everyone,
I'm now facing a issue that number counting won't work correctly when I use Notification Center(I tried to narrow down the problem area as below's code and Notification Center seems to be problem's root)
I suspect that the problem cause from Thread location or reference on NotificationCenter's handler when observing value change. So, I think that If I can change thread location or reference following thread location or reference of the method that defined addObserver.
Am I correct? and does someone know how to make the code correct?
Code is below
ContentView.swift
struct ContentView: View {
@ObservedObject var cht = CompletionHandlerTest()
var body: some View {
Button(action:{
cht.startCount(list: ["A", "B","C", "D", "E"]){ isCompleteCount in
print("countEnd")
}
}){
Text("start")
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
CompletionHandlerTest.swift
import SwiftUI
public class CompletionHandlerTest: ObservableObject {
@Published var counter: Int = 0
private let nbc = NotificationBasedCompletion.shared
func startCount(list: [String], completion: @escaping(Bool) -> Void) {
print("count start")
countTest(items: list, count: 0){ isSuccessful in
completion(true)
print("countTest is finished")
}
}
private func countTest(items: [String], count: Int, completion: @escaping(Bool) -> Void){
if(count >= items.count){
completion(true)
}
else {
print("count in countTest -> \(count)")
nbc.notifyForTest(label: items[count]){ isPrintSuccessful in
print("countTest will call-> count: \(count) + 1")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
self.countTest(items: items, count: count+1) { isCountSuccessful in
completion(true)
}
}
}
}
}
}
NotificationBasedCompletion.swift
final public class NotificationBasedCompletion: NSObject{
public static let shared = NotificationBasedCompletion()
private var observer: NSObjectProtocol?
func notifyForTest(label: String, completion: @escaping (Bool) -> Void ){
if(observer == nil){
observer = NotificationCenter.default.addObserver(forName: NSNotification.Name("notifyStatus"), object: nil, queue: .main){ (_) in
let notifyStatus = UserDefaults.standard.value(forKey: "notifyStatus") as? Bool ?? false
if notifyStatus {
completion(true)
}
}
}
//if below code is used, count won't proceed
generateNotification()
// if below code is used, count will count correctly
//completion(true)
}
private func generateNotification() {
print("let's notify!")
UserDefaults.standard.set(true, forKey: "notifyStatus")
NotificationCenter.default.post(name:NSNotification.Name("notifyStatus"), object: nil)
}
}
When executing above code, then print as below
count start
count in countTest -> 0
let's notify!
countTest will call-> count: 0 + 1
count in countTest -> 1
let's notify!
countTest will call-> count: 0 + 1
count in countTest -> 1
let's notify!
countTest will call-> count: 0 + 1
count in countTest -> 1
I hope that someone knows about the issue.
Best regards,
Post not yet marked as solved
I'm writing an app that needs to present repeating notifications on a schedule. The schedule will be every x months, where x is a number 1-72. So, it could be every 1 month, every 7 months, every 45 months, etc..
This is my first venture into user notifications, and I'm struggling with the DateComponents piece.
I see the documentation says DateComponents.month = a month or count of months. I interpret that to mean that the value could be an Int to represent a specific month (like 1 = January) or an Int to represent the number of months used for repetition (ex: 2 = every 2 months).
For my test, I wanted to manually create a user notification trigger that would repeat every 1 month on the first day of the month at 7:00am.
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
dateComponents.month = 1
dateComponents.day = 1
dateComponents.hour = 7
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
That didn't work as expected. It created the notification for January 1st at 7:00am, rather than the 1st of each month. I expect it would have repeated on the next calendar year.
What am I doing wrong? What is needed to achieve my goal of repeating every x months?
Post not yet marked as solved
Based off the Apple documentation, I expected to see that the notification with the highest relevance score was featured in the Notification Summary. However, when sending several notifications from a single app with the new relevance score field, I am consistently seeing the most recent notification be featured in the Summary — not the one with the highest score. I am using Xcode 13 beta 5 and a device running iOS 15 beta 6.
This is the sample payload sent via APNs (with the relevance score being updated between sends):
{
"aps": {
"alert": {
"title": "Relevance score: 0.4",
"body": "body text here."
},
"interruption-level" : "active",
"relevance-score" : 0.4
}
}
I have also confirmed that the UNNotificationContent object has the relevance score field populated with the expected double when receiving the push on the device.
Post not yet marked as solved
I've deployed couples build to appstoreconnect after integrating push notification by using: /zo0r/react-native-push-notification
But the new build disappeared without any issues, I don't know what is going and what is the root cause because I didn't see any email send to my email if the app got any issue need to fix.
Checked:
Followed instructions on the readme file.
Entitlements are there
Certs are good
Provisioning profile is good
App archived and deploy successful
hint: I tried switching the branch without push-notification then submit a new build and it's appearing.
Post not yet marked as solved
In iOS 15.0 Beta 5 - Normal alert notification overrides to Critical alert notification. Is this issue with iOS 15 beta 5?
I'm unable to see it multiple critical alert notifications only one notification banner at a time. Is it expected behaviour or bug in iOS 15 beta 5?
Can we able to see multiple notifications banner in notification centre for iOS 15 beta 5?
Post not yet marked as solved
Mac App send a banner-Style local Notisfication, but My screen don't show it.
when I check it, it exists in NotisficationCenter。
the code is like this:
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error.description);
}
if (granted) {
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"summary";
content.body = @"title";
if (settings.soundSetting == UNNotificationSettingEnabled) {
content.sound = UNNotificationSound.defaultSound;
}
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:false];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:NSUUID.UUID.UUIDString content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"failure");
}
}];
}
}];
} else {
return;
}
what's more weird is when I use NSUserNotificationCenter to do this operation, the notisfication just "disappear". I can't find it any where.
wish to receive your reply
Post not yet marked as solved
https://stackoverflow.com/questions/68980169/repeating-local-notifications-for-specific-days-of-week-after-certain-start-date
Post not yet marked as solved
Hi,
Now I trying to make up the App environment without AppDelegate,
so here's the question.
how can I access to APNs or use functions like a application function in AppDelegate for subscription of Push Notifications or something?
Post not yet marked as solved
There is a delay when resizing the iOS 15 preferredContentSize widget.
It is the same when setting NCWidgetDisplayModeCompact, NCWidgetDisplayModeExpanded.
Is it possible to adjust without delay?
It seems to be an ios 15 bug.
Post not yet marked as solved
Notification center delegate is firing for local notifications but not remote, when using UNTextInputNotificationAction on a WKUserNotificationInterfaceController.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
I get a response when the user enters text and submits, but only for a local notification. For the remote notification - the delegate method never fires. The notification delegate is a singleton that's assigned in the watch's ExtensionDelegate's applicationDidFinishLaunching method.