Several push notifications being received with iOS - ios

I'm working on an app that has push notifications enabled. My app it's using push notifications since day 1 with parse.com as the server.
Everything was working fine, I did several app updates and improvements and I had always receive one notification for each push sent by the server, I've also updated from parse 1.7.2 to 1.12.0 without having issues.
Because parse.com was going to terminate its services, I started the migration from parse to Urban Airship (using 7.0.2).
I did several tests, installing and uninstalling the app on my phone, installing the production version (using parse) and installing the development version (using urban airship), everything was working fine, when suddenly and I don't know why, I started receiving 5 notifications per push sent by the server. I thought it was a parse.com problem because at that time my iPhone was running the production version (with parse), but it was not.
When the version (using Urban Airship) was just published, I kept receiving 5 notifications.
I'm totally lost here, I don't have any clue why this is happening, at first I thought it was related with the several installs and uninstalls of the app, so I try:
1. Disabling notifications.-
2. Deleting the app.-
3. Disabling notifications
3.a. deleting the app
3.b. then changing time and date ahead a couple of days
3.c. then turning off the phone
3.d. turning on again and putting the right date
3.e. restarting the phone
3.f. installing the app
None of those worked so far. And I couldn't find anything online about this issue that was clear or solve this issue.
I hope someone could help me.
Extra info:
Swift 2
iOS 8.0+
XCode 7
Pushes are sent by a PHP Server
My AppDelegate.swift (Please notice that I have only included the relevant code, the rest of the code is not related):
import UIKit
import CoreData
import AirshipKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let config: UAConfig = UAConfig.defaultConfig()
UAirship.takeOff(config)
UAirship.push().userPushNotificationsEnabled = true
UAirship.push().resetBadge()
// Get the user settings
let userSettings = NSUserDefaults.standardUserDefaults()
var notify = userSettings.dictionaryForKey("notifications")
let appReset = userSettings.objectForKey("appResetv200")
if appReset == nil {
notify = nil
userSettings.setObject("done", forKey: "appResetv200")
}
if notify == nil {
let notificationTypes = [
"notType1" : true,
"notType2" : true,
"notType3" : true
]
userSettings.setObject(notificationTypes, forKey: "notifications")
UAirship.push().addTag("notType1")
UAirship.push().addTag("notType2")
UAirship.push().addTag("notType3")
UAirship.push().updateRegistration()
}
return true
}
}
I hope someone can help me, everything worked fine when I did the tests on my development environment, and now it's a complete mystery why it's failing.

Related

Flutter IOS app not receiving FCM notifications when deployed to test flight

I have a flutter app that i am trying to get Firebase cloud messaging to work on but for some reason it refuses to work when deploying to test flight.
If i run in debug mode through VSCode everything works as it should but as soon as i run flutter build ios and deploy to test flight everything breaks.
I have tried a multitude of solutions over the past couple of days including:
Removing and re-adding all certs & provisioning profiles
changing <key>FirebaseAppDelegateProxyEnabled</key><false/> to <key>FirebaseAppDelegateProxyEnabled</key><string>0<string/> AND to <key>FirebaseAppDelegateProxyEnabled</key><string>NO<string/>
trying to force the APNS token to be a production token by adding this to
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { #if DEVELOPMENT //Develop Messaging.messaging().setAPNSToken(deviceToken as Data, type: .sandbox) #else //Production Messaging.messaging().setAPNSToken(deviceToken as Data, type: .prod) #endif }
I have also tried doing different combinations of the above in the hope that one of the solutions would work in tandem with each other.
if anyone can shed some light on why this might be happening i would be extremely grateful!

Crashes not showing up in Firebase console

I'm trying to transition my iOS app from Crashlytics to Firebase, since Crashlytics is going to be shut down in a month. I went through the steps described here:
https://firebase.google.com/docs/crashlytics/get-started-new-sdk
It all looked great until I tried my first test distribution. I added a piece of code that would crash the app on a button tap to test that I get the crashes from distributed apps. However, it didn't work. The app crashes, but I see no crash reports. I do see that Crash-free users percentage is going down though. So something is getting registered, but the actual crashes are not there.
My fists couple of test distributions were missing DSYMs. And under DSYMs tab I could even see the crash count. However, when I did upload the DSYMs the crashes still didn't appear.
Now I'm using a script that does the DSYM upload on archive, but crashes are not showing up still.
When I do a build using Xcode and force crash everything works as expected. It's only the distributed AdHoc builds don't show any crashes in the portal.
Any kind of help is highly appreciated.
If your forced crash didn't crash, crashed before you wanted it to, or you're experiencing some other issue with Crashlytics, you can enable Crashlytics debug logging to track down the problem.
To enable debug logging on your development device, specify the following command line argument in Xcode:
Crashlytics 3.11.1+
-FIRDebugEnabled
Previous versions
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Initialize Firebase service.
FirebaseApp.configure()
Fabric.sharedSDK().debug = true
return true
}
Boom, after hours of trying and searching.
https://github.com/firebase/firebase-ios-sdk/issues/2901
Disabling bitcode for AdHoc builds fixed it for me.

Firebase Push notifications not working

So my Firebase push notifications are not working on iOS (Simulator + I do not have a developer account, might this be already a reason?)
What I did:
Created an app in Google Firebase (I think I didn't add the fingerprint because I don't have it yet)
Added Firebase/FirebaseMessaging to my Podfile
Added GoogleService-Info.plist to my project Directory
Added Keychain Sharing in Capabilities
Added following code to my App Delegate:
Here is my code:
import Firebase
import UserNotifcations
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.badge, .alert, .sound] {(granted, error) in}
application.registerForRemoteNotifications()
return true;
}
}
Any mistakes? Did I miss something? Is it because I don't have a developer account or is the simulator not capable of receiving push notifications? Any help would be appreciated!
Simulators in Xcode don't receive remote notifications. You have to run it on an actual device. I think Apple allow you to run it on a device without a paid developer account now.
You won' be able to send push notifications without a paid developer account. Not even on a real device.
More information here
The iOS simulator can't receive remote notifications. You have to run the app on your device.

Location based iphone app not working in background after updating to iOS 9.3.1 and above

I have created an app which tracks the location of the user even if the app is in the background or the screen is locked. I have tested it on an iPhone 5s device with iOS 9.2 and everything was working fine. After updating to iOS 9.3.1 I noticed that the app would run for about 10 minutes in the background and then app would automatically stop. I updated the phone to iOS 9.3.2 yesterday hoping that there was a fix for this issue. However the issue still persists.
I have the following code in AppDelegate class
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private static var backgroundService : BackgroundService? = nil
var startServices : Bool = false
public static var bgTask = UIBackgroundTaskIdentifier()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
print("didFinishLaunchingWithOptions")
AppDelegate.bgTask = beginBackgroundUpdateTask()
startBackgroundService()
return true
}
internal func startBackgroundService(){
if AppDelegate.backgroundService == nil{
AppDelegate.backgroundService = BackgroundService.getBackgroundService()
}
AppDelegate.backgroundService!.startService(self)
}
internal func stopBackgroundService(){
AppDelegate.backgroundService!.stopService()
}
func beginBackgroundUpdateTask() -> UIBackgroundTaskIdentifier {
return UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({})
}
func applicationDidEnterBackground(application: UIApplication) {
self.startBackgroundService()
print("applicationDidEnterBackground")
}
}
Background App Refresh and Location Services have been enabled for the app on the iphone. Background mode has been enabled and other required permissions have been added in Info.plist.
The issue is not due to any code changes as I tested the code on another phone with iOS 9.2 and it is working perfectly. After updating the second phone to iOS 9.3.2 the same issue occurred. Has there been any change in 9.3 which is causing this issue? I went through the changelogs and documentation but haven't been able to find anything useful. Has anyone else encountered a similar issue? Is there any changes that I need to do to ensure that the app works with iOS 9.3?
Finally managed to solve the issue. After adding locationManager.allowsBackgroundLocationUpdates = true as suggested the issue still persisted. Although it ran in the background for a longer duration but after a certain point the app stopped fetching location data.
After searching online a bit more I came across this setting
locationManager.pausesLocationUpdatesAutomatically = false
Adding this line solved the issue and the location fetching works in the background without stopping abruptly. The default value for it is true.
As mentioned by #Ahmed and #Chajmz allowsBackgroundLocationUpdates is required in iOS 9 and later
In iOS 9 and later, regardless of deployment target, you must also set the allowsBackgroundLocationUpdates property of the location manager object to YES in order to receive background location updates. By default, this property is NO, and it should remain this way until a time when your app actively requires background location updates.
As per the documentation about CLLocationManager - pausesLocationUpdatesAutomatically
Allowing the location manager to pause updates can improve battery life on the target device without sacrificing location data. When this property is set to true, the location manager pauses updates (and powers down the appropriate hardware) at times when the location data is unlikely to change. For example, if the user stops for food while using a navigation app, the location manager might pause updates for a period of time.
The default value of this property is true.
Since iOS 9, you can avoid using backgroundTaskWithExpirationHandler, if you want to have constant access to your data from your LocationManager you can use allowsBackgroundLocationUpdates however, if you stop your LocationManager in background you won't be able to restart it from background.
if #available(iOS 9.0, *) {
manager.allowsBackgroundLocationUpdates = true
} else {
// Fallback on earlier versions
}

New installations not appearing in Data Explorer - Parse.com

I deleted my installation class in the Parse Data Explorer, and created a new one. Now that it's empty no new installations are appearing in the class. What is causing this behaviour, and how can i fix it. Did Parse implement some kind of function to call in the iOS SDK before an installation can appear?
Any help is appreciated! :)
If you delete records from Installation table, the records will not appear again when you open your App. This easy fix is to delete the App from your device and re-install it for a device Installation record to appear again in your class. This is possibly because when you register an installation it gets cached locally by the Parse SDK on your device and will not be updated again.
I tried to do the push guide from Parse again, and it seemed like they changed some thing in the SDK, which caused the problem!
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
PFPush.storeDeviceToken(deviceToken)
let currentInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.channels = ["global"]
currentInstallation["notifyEnabled"] = true
currentInstallation.saveInBackground() //This line was not there initially!
}
I fixed it by inserting the line highlighted in the code.
Thanks for the all the help! :)

Resources