NotificationCenter

RSS for tag

Create and manage app extensions that implement Today widgets using NotificationCenter.

NotificationCenter Documentation

Posts under NotificationCenter tag

74 Posts
Sort by:
Post not yet marked as solved
0 Replies
43 Views
I'm Facing an issue when i Debug Project in Real Device, I'm Getting Notification With Custom Sound, But After making a Build Via Diwai, I'm Not Getting Custom Sound, It Play Default Sound with Notification.I'm Using Firebase. I have Added Custom Sound in Project and added in Bundle Resources as well. Please Have A look on My Code. Here's My Code func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let content = UNMutableNotificationContent() content.sound = UNNotificationSound(named:UNNotificationSoundName(rawValue: "EigenIntro.caf")) FirebaseApp.configure() Messaging.messaging().delegate = self if #available(iOS 10.0, *) { // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions, completionHandler: { _, _ in } ) } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } Messaging.messaging().token { token, error in if let error = error { print("Error fetching FCM registration token: \(error)") } else if let token = token { print("FCM registration token: \(token)") } } application.registerForRemoteNotifications() return true } func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { print("Firebase registration token: \(String(describing: fcmToken))") self.sendDataToServer(token: fcmToken!) } func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo print(userInfo) completionHandler([[.alert, .sound, .badge]]) } func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo print(userInfo) completionHandler() } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let token = deviceToken.hexString print("APNs Device Token: \(token)") Messaging.messaging().apnsToken = deviceToken Messaging.messaging().setAPNSToken(deviceToken, type: .prod) } func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { Messaging.messaging().appDidReceiveMessage(userInfo) completionHandler(.noData) }
Posted
by
Post not yet marked as solved
0 Replies
42 Views
AVFoundation have these notifications like AVCaptureDeviceWasConnected, AVCaptureDeviceWasDisconnected, AVPlayerItemDidPlayToEndTime, AVPlayerItemFailedToPlayToEndTime, etc., that inform if a device was connected or disconnected, if the video paused, stop, ended, etc. Is there some similar for airdrop? I means if files are airdropped, which files were airdropped, etc? I need to receive a list of files that were airdropped to macOS when that happens. Is that possible to know that, by notifications or other means?
Posted
by
Post not yet marked as solved
0 Replies
54 Views
In my iOS/iPadOS app I have notification content extension, which presents extended content using WKWebView. However, when started on lock screen (locked device), WKWebView does not load data properly. Therefore, I would like to ask user to unlock the device before displaying content. This is how Apple Mail does that - when selecting (long-pressing) notification banner on lock screen, it presents unlock screen (Passcode screen) before displaying content. Question: Do you know, how to do that? Is there any API to present unlock screen programmatically?
Posted
by
Post not yet marked as solved
0 Replies
75 Views
I want to open Instagram by clicking on the button in the expanded push notification. To do this, I use the following line: extensionContext.open(URL(string:"instagram://")!) in the button action. When I click on the button, a warning may appear about transition to another application. After the alert I can go to the app and it works perfectly. But if I try to go to instagram from Notification Center or through a locked screen, nothing will happen. Although a warning about the transition will appear, Instagram doesn't open if you click confirm. Does anyone know how to fix this? P.S. is it possible to somehow remove the alert of transition to another application?
Posted
by
Post not yet marked as solved
2 Replies
204 Views
Is there any way to run code in iOS whenever new information are added to certain contacts in contact store? If I use Notifications, I would have to have a process running at all times, since contacts are able to be changed by Apple's Contacts app. I have looked at App Extensions and there are no extensions I that can be used. There is a way to run a background process but I recall that has a limited lifespan. Am I correct about this? I need to update data in CloudKit that saves contacts information that can be shared with other users using their own Apple ID's. CloudKit subscriptions notify my app when something changes in CloudKit, but I also need to update records in CloudKit when something changes in Contacts. Anyone have any ideas how this might possibly be done?
Posted
by
Post not yet marked as solved
0 Replies
164 Views
Hello everyone! I am trying to implement push notifications in my WatchOS app. I have created the delegate class that handles the registration for remote notifications and that allows me to obtain the device token. Then I take the token and send it to Firebase, like this: func didRegisterForRemoteNotifications(withDeviceToken deviceToken: Data) {     FirebaseApp.configure()     var ref: DatabaseReference!     ref = Database.database().reference().ref.child("/")     let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }     let token = tokenParts.joined()      if let userID = UserDefaults.standard.object(forKey: "id") as? String {         ref.child("users/\(userID)/token").setValue(token)     } } Then I am using a Python Script to communicate with APNS. I am using the http library to get access to HTTP2. This is what I have got: payload = { "aps" : { "alert" : { "title" : "Hello Push", "message": "This is a notification!" }, "category": "myCategory" } } dev_server = "https://api.sandbox.push.apple.com:443" device_token = "9fe2814b6586bbb683b1a3efabdbe1ddd7c6918f51a3b83e90fce038dc058550" headers = { 'method': 'POST', 'path': '/3/device/{}'.format(device_token), 'autorization': 'bearer' + 'provider_token', 'apns-push-type': 'myCategory', 'apns-expiration': '0', 'apns-priority': '10', } async def test(): async with httpx.AsyncClient(http2=True) as client: client = httpx.AsyncClient(http2=True) r = await client.post(dev_server, headers=headers, data=payload) print(r.text) asyncio.run(test()) I have also downloaded the .p8 auth key file. But I don't really understand from the Apple Documentation what I have to do with it. What is the provider token in the headers? Am I doing the right thing with the token I receive from didRegisterForRemoteNotifications?
Posted
by
Post not yet marked as solved
2 Replies
153 Views
good day, I need help with see below when the notification is OK, the badge is added. If the application is opened the badge disappears. that is right. when a new notification arrives badge it is not 1 but the value is previous value +1. I need the value to be 0 when the application is opened. it's about resetting the badge value. I don't know if this code Is correct for my functionality. func applicationDidBecomeActive (_ application: UIApplication) { UIApplication.shared.applicationIconBadgeNumber = 0 } the value does not reset but only disappears.
Posted
by
Post not yet marked as solved
0 Replies
182 Views
It has appeared 3~4times on different ios15 phones. when app not running, provider push two notifications(background+ normal). the notification service extension logs that the normal push was received, but banner not present and tone not alarm, app not awaked(there is no problem with the settings on the device). when lanch the app manually about 30s later, app logs that the background push received("application:didReceiveRemoteNotification:fetchCompletionHandler" called). It seems that ios system block or delay handle the remote notifications, has anyone encountered the same problem?
Posted
by
Post not yet marked as solved
0 Replies
147 Views
Hi Team , I am facing an issue with one of the scenario in Actionable Push Notification. Case: On long press of notification , we get two actions "Accept" and "Review". On click of Accept , an api call triggers. If the API call is success we don't have to do anything but if the api call fails , we have to open the app and redirect the user to specific screen on app. There is a option to get the app on foreground on click on Accept Button, since app should not open on click of accept button but it should open when the api call gets fail on click on accept button that option is of no use. Another option I tried is to use openURL method, that also doesn't work when the app is in background How can I solve this ?
Posted
by
Post not yet marked as solved
0 Replies
177 Views
Problem: Need to create an app (General) that will start/stop and manage other apps (Secondary). The general app will be only one, but secondary apps will be as many as user want. As well the general app should communicate with secondary apps. PS: The secondary app MUST start only as a separated instance app. Question: I want to know your thoughts, adviсes, and best practices for: Should I create one Xcode project with two targets (General and Secondary)? Or should I create two different Xcode projects? As for me: maybe one of the best solution will be the second one with using some ci/cd. What do you think? How the general app should communicate with second apps? As for me: Could Distributed Notifications helps in this situation? Thank you, I will be glad for any information, word, or sources.
Posted
by
Post not yet marked as solved
0 Replies
164 Views
Hello there, I'm using firebase to push notification with data is: { "notification": { "title": "Title notification", "category": "GENERAL", "body": "body notification", "sound": "default" }, "mutable_content": true, "data": { "title": "Title message", "body": "Body message.", "idhit": "a043dada-1208-4067-b5b6-50bc8578bfc3", "gmtdatetimeid": "620989200", "typehit": 0, "carnumber": "ABC123", "alertname": "Unauthorized Vehicle", "gmtDatetime": "2020/06/05 07:28:30.929", "latitude":"10.792332496703715", "longitude":"106.68018372088815" }, "registration_ids": [ "eBStmdlNfUzJghm1KwpKr-:APA91bGcqODroQnUKKOvJmlg3Vs1ej9Zq-" ] } when my app receive data, i want to get GPS of device and compare it with gps from notification. How do did it, thanks!!!
Posted
by
Post not yet marked as solved
0 Replies
207 Views
I have an app that uses local notifications and everything is working fine but I'm debating how to handle pending notifications after the user turned off and turned back on notifications for your app. In other words, let's say that a notification is created and it's meant to be triggered on a certain day but the user turns notifications off the day before the trigger date, then he/she deletes the notification from the app (UI) while notifications for your app were turned off and then after a few days later the user turns on notifications for your app again, at that point there may be notifications that the user no longer wants (since he/she deleted them from the UI) and some that have been expired already. How to find pending notifications that were deleted from the UI but not from the notification center in the event described above? FYI - I know how to delete pending notifications and how to compare notifications in the UI vs notifications in the notifications center. What I'm not sure about is when to do the comparison. Is there a way to get notified when the user turned back on notifications for your app so a method can be triggered to find orphan notifications? Thanks!
Posted
by
Post not yet marked as solved
0 Replies
268 Views
I am trying to add time sensitive notifications to my task/reminder app, but I am having some difficulty. Here is the code I am using currently: let center = UNUserNotificationCenter.current() let content = UNMutableNotificationContent() content.title = "Productivi" // that's the name of the app content.body = "\(taskObject.content)" //task content content.categoryIdentifier = "TASK_REMINDER" if #available(iOS 15,*) { print("Using ios 15 for set notification") content.interruptionLevel = .timeSensitive } For the adding notification request, that part works, however when the notification shows up, it isn't a time sensitive one. (I was testing in simulator and on my phone both running iOS 15.4) I can't figure out what else there is I have to do in order to enable the feature. I've done everything it says to do, is their an entitlement or capability I have to add. If so, what is it called and can some one please give me detailed steps on how to add that for local notifications in XCODE? Thank you, -Rohan
Posted
by
Post not yet marked as solved
1 Replies
264 Views
I can successfully connect and show ExternalView() on the external display on IOS target. However, mac catalyst is unable to detect the display connection in NotificationCenter. How do I use NotificationCenter in mac catalyst to detect and connect an external display? import Combine import SwiftUI @main struct ScreensApp: App {   @ObservedObject var externalDisplayContent = ExternalDisplayContent()   @State var additionalWindows: [UIWindow] = []   private var screenDidConnectPublisher: AnyPublisher<UIScreen, Never> {     NotificationCenter.default       .publisher(for: UIScreen.didConnectNotification)       .compactMap { $0.object as? UIScreen }       .receive(on: RunLoop.main)       .eraseToAnyPublisher()   }   private var screenDidDisconnectPublisher: AnyPublisher<UIScreen, Never> {     NotificationCenter.default       .publisher(for: UIScreen.didDisconnectNotification)       .compactMap { $0.object as? UIScreen }       .receive(on: RunLoop.main)       .eraseToAnyPublisher()   }   var body: some Scene {     WindowGroup {       ContentView()         .environmentObject(externalDisplayContent)         .onReceive(           screenDidConnectPublisher,           perform: screenDidConnect         )         .onReceive(           screenDidDisconnectPublisher,           perform: screenDidDisconnect         )     }   }   private func screenDidConnect(_ screen: UIScreen) {     print("connected")     let window = UIWindow(frame: screen.bounds)     window.windowScene = UIApplication.shared.connectedScenes       .first { ($0 as? UIWindowScene)?.screen == screen }       as? UIWindowScene     let view = ExternalView()       .environmentObject(externalDisplayContent)     let controller = UIHostingController(rootView: view)     window.rootViewController = controller     window.isHidden = false     additionalWindows.append(window)     externalDisplayContent.isShowingOnExternalDisplay = true   }   private func screenDidDisconnect(_ screen: UIScreen) {     print("disconnected")     additionalWindows.removeAll { $0.screen == screen }     externalDisplayContent.isShowingOnExternalDisplay = false   } }
Posted
by