Local notifications not showing in notification center (.provisional) / iOS 15.2.1 - apple-push-notifications

Has anyone experienced problems with [.provisional] notifications on iOS 15? Can't get anything to show up in Notification Center in 'Quiet Delivery' mode. I'm clueless..
These are relevant extracts:
UNUserNotificationCenter.current().requestAuthorization([.provisional, .alert])
// -> granted: true
let content = UNMutableNotificationContent()
content.title = "Test"
content.body = "Test"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: "some_id...", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)}
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification, ...)
// This is called -> returning [.banner] (so it should show in foreground, not that it matters since it's provisional...)
BUT ... notifications center is empty.
The same code works fine using non-provisional mode (user granting explicit consent to notifications).
Is there something obvious I might be missing here?
--
UPDATE: Ok, not much of an answer, but clear observation:
Putting app into background -> above code does deliver notification into notification center.
This means that .provisional mode completely ignores 'willPresent notification:' return value [which allows presentation in foreground] AND does not deliver notification into notification center if app is in foreground.
I guess I can live with that and it kind of makes sense... (?).

Related

xcode 12 firebase notification when app in background how to do a reload if the app have a opened webview

I implemented firebase notification in Xcode 12 via cocoapod and basic step by step... notification ARE working all nice and good, even when app in background.
this tutorial : https://www.appcoda.com/firebase-push-notifications/
the only thing I need is this condition : when App in background and user hit the notification, it opens the APP, but I want the webview to reload.
i think it would be in this part of the code
// [START receive_message]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
but what code and I add to reload the view ?
// [START receive_message]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: (messageID)")
}
// Print full message.
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}

iOS 12 present(fromrootviewcontroller) causes app to freeze

Very confused about an issue I've just stumbled across.
I have a swift game, mainly using SpriteKit.
At the end of a game an ad is loaded. Or when the user decides to end the game an ad is also loaded.
If the game is played normally. The flow is as follows...
MenuScene -> GameScene -> [ad loads] -> GameOverScene
If the user quits the game...
MenuScene -> GameScene -> user selects pause -> user clicks quit -> [ad loads] -> Menu Scene
Both scenarios work perfectly for iOS 13
However, in iOS 12, only the user quitting mid game works, in the other scenario the app freezes (no obvious errors to me in the log)
Ending a game, via either method, calls the exact same function. Which uses a notification to load the ad.
The following code is all in the GameViewController. And the notification is posted in the GameScene.
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.showAd), name: NSNotification.Name(rawValue: "loadAndShow"), object: nil)
An ad is prepared in ViewDidLoad()
myAd = createAd()
And the function is called by the Notification
#objc func showAd() {
if (myAd.isReady) {
myAd.present(fromRootViewController: self)
myAd = createAd()
}
}
func createAd() -> GADInterstitial {
myAd = GADInterstitial(adUnitID: "MY ADMOB ID")
let request = GADRequest()
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = ["MY DEVICE ID"]
myAd.delegate = self
myAd.load(request)
return myAd
}
Any help would be amazing
UPDATE
Have found a potential workaround.
Am now presenting the ad in a different thread and no longer experiencing any freezing.
DispatchQueue.main.async {
self.myAd.present(fromRootViewController: self)
}
Can only assume iOS13 has better handling for this. And the reason the "game quit" scenario worked was because it was transitioning to the menu scene which is also the GameViewController. The app didn't like presenting an ad from the GameViewController while also transitioning to a new scene.

UIActivityViewController display is scrolled in last iOS11 GM on iPhone7Plus

Since the last release of iOS11 (GM version), the activity view is displayed scrolled to the top, with a spring resistance preventing the user to 'unscroll' it.
Previous version of iOS 11 (beta version) never suffered from this, nor iOS 10.
Also, one can see a blank margin at the bottom plus the fact that the preview image is not fetched/displayed right in the Website preview.
Here is the code. Any idea?
let textToShare = "\(message) (\(share))"
let objectsToShare : [Any] = [textToShare, url]
let activityViewController = UIActivityViewController(activityItems: objectsToShare as [AnyObject], applicationActivities: nil)
// New Excluded Activities Code
activityViewController.excludedActivityTypes = [.airDrop, .addToReadingList]
activityViewController.completionWithItemsHandler = {
(activityType: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error? ) -> Void in
_completed(completed)
}
Ok. It’s only Twitter app itself that had to be updated for iOS11 (as in iOS11, there is no longer centralized system, sharing is handled by apps such as Facebook or Twitter themselves).

iOS 10 push notification when app terminated?

I'm face the problem after upgraded to iOS 10 about push notification (I am using Swift3).
In normal case when application open or application still in background everything work as well (can receive push notification and update data as my logic).
But when application is terminated i can't handle push notification when application become active.
Here is my test case.
Edit Scheme to Wait for executable to be launched.
Double press home button and swipe application up.
Run Xcode wait until "Wait for application to launch" shown.
Test send push notification from server.
Device received push notification.
Start application from application icon.
After that application start and didFinishLaunchingWithOptions being called but launchOptions aways null so i can't handle push notification (But if i open application from notification in notification center or popup notification launchOptions is not null)
Does anybody has any idea to check this problem ?
Thank you in advance.
You need to open the application by tapping the push notification in the notification tray.
When you launch the application from the icon, launchOptions will be nil. Launching from the push notification will provide you launchOptions.
https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622921-application
Try this:
Add delegate on AppDelegate.
UNUserNotificationCenterDelegate
And..
//Called when a notification is delivered to a foreground app.
#available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
print("User Info = ",notification.request.content.userInfo)
completionHandler([.alert, .badge, .sound])
}
//Called to let your app know which action was selected by the user for a given notification.
#available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
print("ActionIdentifier = ",response.actionIdentifier)
print("User Info = ",response.notification.request.content.userInfo)
completionHandler()
}

How to get resolution change event in swift?

I try to make an app, and now i shoud make some changes when screen resolution will change, but i coudn't find how to intercept this event.
Do you have any ideea how can i take that event?
The NSApplicationDidChangeScreenParametersNotification is posted when the configuration of the displays attached to the computer is changed, so
you can register for that notification, e.g. with
NSNotificationCenter.defaultCenter().addObserverForName(NSApplicationDidChangeScreenParametersNotification,
object: NSApplication.sharedApplication(),
queue: NSOperationQueue.mainQueue()) {
notification -> Void in
println("screen parameters changed")
}
Note that there can be various reasons why this notification is
fired, e.g. a change in the dock size (as observed in Cocoa Dock fires NSApplicationDidChangeScreenParametersNotification), so you have to
"remember" the old resolution and compare it with the new resolution.
Swift 4:
The didChangeScreenParametersNotification is posted when the configuration of the displays attached to the computer is changed.
Inside the func applicationDidFinishLaunching() in AppDelegate class or func viewDidLoad() in ViewController class, insert the following code:
NotificationCenter.default.addObserver(forName: NSApplication.didChangeScreenParametersNotification,
object: NSApplication.shared,
queue: OperationQueue.main) {
notification -> Void in
print("screen parameters changed")}
I personally, used it to center the position of my application when switching between the Mac and the external screen.
Here is the updated Swift 3 code:
NotificationCenter.default.addObserver(forName: NSNotification.Name.NSApplicationDidChangeScreenParameters,
object: NSApplication.shared(),
queue: OperationQueue.main) {
notification -> Void in
print("screen parameters changed")
}
Code for Swift 5+
NotificationCenter.default.addObserver(
forName: NSNotification.Name(rawValue: "NSApplicationDidChangeScreenParametersNotification"),
object: NSApplication.shared,
queue: .main) { notification in
self.adjustUIIfNeeded()
}

Resources