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.
Related
I created an APP for both iOS and Android and I used APN to get deviceToken for iOS and GCM for Android. I decided to migrate to firebase to make token management easier. I noticed a issue just for iOS application and I was wondering if someone else encountered it too.
When I migrated iOS app to firebase, token was not regenerated unless the app was reinstalled. I follow the firebase guide to do it but with no result.
Someone else has this problem?
Thanks in advance
I solved my problem.
I switch off and switch on capabilities
I restarted XCode
I put FIRInstanceIDAPNSTokenType to prod and now all seems to work
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) {
FIRInstanceID.instanceID().token()
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.prod)
}
I followed all the steps correctly to install Firebase to my iOS App and it still doesn't work. In the application method, I added FIRApp.configure() like so:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
return true
}
And I keep receiving NSException errors. Firebase seems to work on my Android Project, what's the deal with iOS?
I believe this is some sort of Swift 3 issue, because I encountered a similar problem. After looking over the internet, I believe that Firebase 3 hasn't updated to recent Swift Syntax located in Swift 3. Many other developers are having trouble with it as well. As an alternative, you could switch back from Xcode 8 and into 7, which would allow you to create your application which will work with current IOS, and when Firebase updates, it will be easy for you to migrate to Swift 3.
Hope this helps,
Morgan Gallant
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.
My app has background modes enabled with Background Fetch checked and I validated the plist includes the appropriate fetch mode.
I have also configured the interval as follows:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum);
return true;
}
And I have added the handler as follows:
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Get some new data here
completionHandler(UIBackgroundFetchResult.NewData);
}
I tried going to Debug->Simulate Background Fetch, but no matter what it never enters the performFetchWithCompletionHandler. I also tried to run the app under a scheme that has the "Launch due to a background fetch event" option checked. Running under this scheme simply launches the application as usual in the simulator with no call to performFetchWithCompletionHandler.
Any ideas?
Thank you!
EDIT: This appears to be affecting the release version of my app as well so it may not be isolated to the simulator. I am running Swift 1.2.
EDIT 2: My bug report was just closed because it is a duplicate of another bug report outlining the same issue. There is still no information confirming the issue is isolated to the simulator.
EDIT 3: No mention of a fix in the Xcode 6.4 Beta 2 release notes. :-(
Here's the only way I've found to test background fetch.
Edit your scheme
Select Run
Select Options
Check the "Launch due to background fetch event" option
Plug-In your iOS Device and run the application on it. It does not work in the iOS Simulator.
Take a look on the XCode release note: https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
"The Xcode menu command Simulator Background Fetch does not work.
Use the menu command in iOS Simulator instead. (20145602)"
You can create your own background fetch push notification to your real device via Houston
install Houston: Open Terminal app and use sudo gem install houston
create PEM certificate for your app Generate .pem file Used to setup Apple PUSH Notification
Get your device token from
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
run Terminal and use
for usual push notification: apn push "<your_device_token>" -c /path/to/apple_push_notification.pem -m "Hello from the command line!"
for background fetch push notification: apn push "<your_device_token>" -c /path/to/apple_push_notification.pem -n
More options for apn app:
c.option '-m', '--alert ALERT', 'Body of the alert to send in the push notification'
c.option '-b', '--badge NUMBER', 'Badge number to set with the push notification'
c.option '-s', '--sound SOUND', 'Sound to play with the notification'
c.option '-y', '--category CATEGORY', 'Category of notification'
c.option '-n', '--[no]-newsstand', 'Indicates content available for Newsstand'
c.option '-d', '--data KEY=VALUE', Array, 'Passes custom data to payload (as comma-delimited "key=value" declarations)'
c.option '-P', '--payload PAYLOAD', 'JSON payload for notifications'
c.option '-e', '--environment ENV', [:production, :development], 'Environment to send push notification (production or development (default))'
c.option '-c', '--certificate CERTIFICATE', 'Path to certificate (.pem) file'
c.option '-p', '--[no]-passphrase', 'Prompt for a certificate passphrase'
In Xcode 8.3.2 this problem doesn't exist. Debug->Simulate Background Fetch does its job. It even works on a simulator.
This method is called.
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
}
you forgot to write #escaping after completionHandler
I am implementing the Pares iOS SDK but am unable to add new installs to the Data Browser. I have seemingly all the correct code and provisioning profiles. I am running iOS 8. What am I missing here?
****EDIT****
I have noticed that on older versions of iOS, devices do seem to be added.
You need to add the following function to your AppDelegate file.
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
UIApplication.sharedApplication().registerForRemoteNotifications()
}
My attempt at rewriting it in Objective-C (it's been a while).
-(void) application:(UIApplication*) application didRegisterUserNotificationSettings: (UIUserNotificationSettings*) notificationSettings {
[[UIApplication sharedApplication] registerForRemoteNotifications];
}