Hi I'm trying to set Parse. Anyone let me know is this steps right?
And where is put this code?
PFAnalytics.trackAppOpenedWithLaunchOptions(nil)
Anyone check my init step?
I think It will helps other new Parse Users.
Thanks
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Hidden statusbar
UIApplication.shared.isStatusBarHidden = true
// Override point for customization after application launch.
Parse.enableLocalDatastore()
Parse.setLogLevel(PFLogLevel.info);
//Initialize Pare
let config = ParseClientConfiguration(block: {
(ParseMutableClientConfiguration) -> Void in
//back4app
ParseMutableClientConfiguration.applicationId = "xxxxxxxxx";
ParseMutableClientConfiguration.clientKey = "xxxxxxxxx";
//Parse LiveQuery Server
ParseMutableClientConfiguration.server = "https://xxxxxxxxx/";
});
Parse.initialize(with: config);
//Initialize Facebook
PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions)
PFTwitterUtils.initializeWithConsumerKey("xxxxxx", consumerSecret: "xxxxxx")
PFUser.enableAutomaticUser()
buildUserInterface()
// color of window
window?.backgroundColor = UIColor.white
//Set Fabric
Fabric.with([Crashlytics.self])
//register ParseSubclass
configureParse()
let userNotificationTypes: UIUserNotificationType = [.alert, .badge, .sound]
let settings = UIUserNotificationSettings(types: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
Your appdelegate is fine! Unfortunately parse-server doesn't support PFAnalytics at this time. So that will not work.
You would have to make use of other tools such as Google , fabric's etc.
I noticed you tagged swift to your question. Your setup is objective C but with swift its different.
Swift 3
// Init Parse
let configuration = ParseClientConfiguration {
$0.applicationId = "XXX"
$0.clientKey = "XXX"
$0.server = "XXX"
$0.isLocalDatastoreEnabled = true
}
Parse.initialize(with: configuration)
PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions);
PFConfig.getInBackground{(config: PFConfig?, error: Error?) -> Void in
if error == nil {
//print(config?["OfflineMode"])
}
}
You will also need to add FBSDKApplicationDelegate outside the didFinishLaunchingWithOptions
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}
Also don't forget to add the frameworks for the selective social platforms or analytics you use. In that instance i would suggest using CocoaPods as a dependency manager.
Works with Swift & Objective C.
Related
How can I go to another view controller after successfully signing with google? I've tried "self.inputViewController?.performSegue(withIdentifier: "goToMain", sender: self)" in my App Delegate but not getting any respond. Am I supposed to add the method in App Delegate or the view controller with the sign-in button?
App Delegate
import UIKit
import Firebase
import GoogleSignIn
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate{
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
GIDSignIn.sharedInstance()?.clientID = "my_client_id"
GIDSignIn.sharedInstance()?.delegate = self
return true
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print(error)
return
}
guard
let authentication = user?.authentication,
let idToken = authentication.idToken
else {
return
}
let credential = GoogleAuthProvider.credential(withIDToken: idToken,
accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { authResult, error in
if let error = error {
let authError = error as NSError
print(authError.localizedDescription)
return
}
self.inputViewController?.performSegue(withIdentifier: "goToMain", sender: self)
}
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url)
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
Are you sure about the inputViewController is not nil? This may a reason for not working.
You can add a function to test this, or you can use the print function to check, or, you can use debug point to check inputViewController is nil or not.
I'd like to add comment but I don't have enough reputation point :).
Good luck.
I am following this tutorial from Firebase to implement Direct Links into my app: Firebase Dynamic Links
My code in my app delegate never seems to run properly. When I run the project I am able to use the link and open the app. But none of the print statements will run so I can't tell if it ran successfully or not:
import UIKit
import Firebase
#main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
func handleincomingDynamicLink(_ dynamicLink: DynamicLink) {
guard let url = dynamicLink.url else {
print("Thats weird. My dynamic object link has no url")
return
}
print("Your incoming link parameter is \(url.absoluteString)")
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
let handled = DynamicLinks.dynamicLinks()
.handleUniversalLink(userActivity.webpageURL!) { dynamiclink, error in
guard error == nil else {
print("Found an error! \(error!.localizedDescription)")
return
}
if let dynamicLink = dynamiclink {
self.handleincomingDynamicLink(dynamicLink)
}
}
return handled
}
#available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
return application(app, open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey
.sourceApplication] as? String,
annotation: "")
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?,
annotation: Any) -> Bool {
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
return true
}
return false
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
Xcode gives me this error after I use the link:
[connection] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"
use below delegate method in SceneDelegate Class:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity)
I am adding the Firebase Dynamic Links in my iOS App. I made the configuration according to the documentation and until this point, all right.
When testing, I noticed that the link opens the app and calls the method:
application (_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]
And works!
But when I click the link (dynamic link) again, it just opens the app and does not call the method.
Can someone help me?
My code:
private func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
// let vc = NomeStoryboard.instance.configuracoes.instantiateViewController(withIdentifier: "idSB_ConfiguracoesApp_Onboard") as! ConfiguracoesAppPageViewController
// UIApplication.shared.keyWindow?.rootViewController = vc
}
return handled
}
#available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
return application(app, open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: "")
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
// Handle the deep link. For example, show the deep-linked content or
// apply a promotional offer to the user's account.
// ...
return true
}
return false
}
}
Make sure didFinishLaunchingWithOptions returns true.
Looks like you have a slightly older version of continueUserActivity -- maybe try the more modern signature:
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
My application cannot call didRegisterForRemoteNotificationsWithDeviceToken on iOS10 devices, even the same code can call it on iOS11 devices.
I don't know why it happening and how to solve this issue.
If anyone knows answers, please help me.
my environment is below:
Xcode: 9.2
Swift: 3.2
deployment target: 10.0
my code is below:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert, .badge, .sound]) {granted, error in
if error != nil {
return
}
if granted {
DispatchQueue.main.async(execute: {
UIApplication.shared.registerForRemoteNotifications()
})
}
}
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = String(format: "%#", deviceToken as CVarArg) as String
let tokenWithoutSpace = token.replacingOccurrences(of: "[ |<>]", with: "", options: .regularExpression)
print(tokenWithoutSpace)
}
Thank you for your help.
Attempting to work with Firebase to register for remote notifications however when implementing the following code I get the error:
UNUserNotificationCenter is only available on iOS 10.0 or newer
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var soundID: SystemSoundID = 0
let soundFile: String = NSBundle.mainBundle().pathForResource("symphony", ofType: "wav")!
let soundURL: NSURL = NSURL(fileURLWithPath: soundFile)
AudioServicesCreateSystemSoundID(soundURL, &soundID)
AudioServicesPlayAlertSound(soundID)
Fabric.with([Twitter.self])
//Firebase configuration
FIRApp.configure()
//Resource code from stackoverflow to create UNUserNotificationCenter
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
application.registerForRemoteNotifications()
return true
}
By doing a simple "Fix-it" doesn't resolve my issue by creating an if statement based on the OS version number. What should I be doing or thinking towards this solution for the UserNotifications framework?
For one thing, with the new UNUserNotificationCenter, you only want to register for remote notifications if the user grants permission. The way your code is setup, you're trying to do it regardless of permission which could be one of the reasons. You should do something like this:
import UserNotifications
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
return true
}
If you need to check if the user has an OS lower than iOS 10.0 - you could try something like this to include the old system:
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
} else {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil))
}
Let me know if this works, and if it's what you're trying to accomplish. If not, I'll remove my answer.