Closed premkumarsepuri closed 4 years ago
Checklist
- [x] I've updated to the latest released version of the SDK
- [x] I've searched for existing GitHub issues
- [x] I've looked for existing answers on Stack Overflow, the Facebook Developer Community Forum and the Facebook Developers Group
- [x] I've read the Code of Conduct
- [x] This issue is not security related and can safely be disclosed publicly on GitHub
Environment
Describe your dev environment here, giving as many details as possible. If you have them, make sure to include:
- Xcode Version:
X.X.X
- Swift Version:
X.X.X
(if issue is Swift related)- Installation Platform & Verison:
[Cocoapods|Carthage|Manual]
versionX.X.X
Goals
What do you want to achieve?
Expected Results
What do you expect to happen?
Actual Results
What actually happened? Can you provide a stack trace?
Steps to Reproduce
What are the steps necessary to reproduce this issue?
Code Samples & Details
Please provide a code sample, as well as any additional details, to help us track down the issue. If you can provide a link to a test project that allows us to reproduce the issue, this helps us immensely in both the speed and quality of the fix.
Note: Remember to format your code for readability:
// INSERT YOUR CODE HERE var example = "Example code" ```// // AppDelegate.swift // CollectionView // // Created by Falin on 21/8/19. // Copyright © 2019 Poket. All rights reserved. //
import UIKit import CoreLocation import FBSDKCoreKit import UserNotifications import LanguageManager_iOS import LanguageKit import STPopup import FBSDKShareKit import FacebookShare import Social
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, SharingDelegate {
func sharer(_ sharer: Sharing, didCompleteWithResults results: [String : Any]) {
print("DONE")
}
func sharer(_ sharer: Sharing, didFailWithError error: Error) {
print("failed")
}
func sharerDidCancel(_ sharer: Sharing) {
print("did cancel")
}
var window: UIWindow?
var globalDeviceTokenID = String()
var pref = UserDefaults()
var locationManager: CLLocationManager!
var responsedata = PPNCMDResponseDataModel()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window?.makeKeyAndVisible()
locationManager = CLLocationManager()
locationManager?.delegate = self as? CLLocationManagerDelegate
locationManager?.requestAlwaysAuthorization()
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "JosefinSans-Regular", size: 10)!], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "JosefinSans-Regular", size: 10)!], for: .selected)
// self.shareCardOnFaceBook()
// LanguageManager.shared.defaultLanguage = .en // LocalizationSystem.sharedInstance.setLanguage(languageCode: "en")
if(!pref.bool(forKey: "isLoggedin")) {
let storyBoard: UIStoryboard = UIStoryboard(name:"Main" ,bundle:nil)
let loginVc: UIViewController = storyBoard.instantiateViewController(withIdentifier: "LoginMainViewController")
let frontVc:UINavigationController = UINavigationController.init(rootViewController: loginVc)
self.window?.rootViewController = frontVc
}
self.pref.set(0, forKey: "Filter")
let language = pref.string(forKey: "languageID")
if language != nil {
let langInt = Int(language!)
if langInt == 1 {
LanguageManager.shared.defaultLanguage = .en
LocalizationSystem.sharedInstance.setLanguage(languageCode: "en")
}else if langInt == 2 {
LanguageManager.shared.defaultLanguage = .ja
LocalizationSystem.sharedInstance.setLanguage(languageCode: "ja")
}else {
LanguageManager.shared.defaultLanguage = .zhHant
LocalizationSystem.sharedInstance.setLanguage(languageCode: "zh-Hant")
}
}else{
LanguageManager.shared.defaultLanguage = .en
LocalizationSystem.sharedInstance.setLanguage(languageCode: "en")
self.pref.set(1, forKey: "languageID")
}
let systemVersion = UIDevice.current.systemVersion
let deviceModel = UIDevice.current.name
pref.set(systemVersion, forKey: "iOSVersion")
pref.set(deviceModel, forKey: "deviceModel")
if let text = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
print(text)
pref.set(text, forKey: "SoftwareVersion")
}
let network : NetworkServiceFace = NetworkServiceFace()
network.updatepns()
UIApplication.shared.registerForRemoteNotifications()
registerForPushNotifications()
if(self.pref.bool(forKey: "isLoggedin")) {
self.ppnCommandCall()
}
// if(pref.bool(forKey: "isLoggedin")) { // let story = UIStoryboard(name: "Main", bundle: nil) // let tabVC = story.instantiateViewController(withIdentifier: "myTabbarControllerID") as! UITabBarController // // let names = [LocalizationSystem.sharedInstance.localizedStringForKey(key: "Get", comment: "Get"),LocalizationSystem.sharedInstance.localizedStringForKey(key: "Wallet", comment: "Wallet"),LocalizationSystem.sharedInstance.localizedStringForKey(key: "Inbox", comment: "Inbox"),LocalizationSystem.sharedInstance.localizedStringForKey(key: "More", comment: "More")] // var index = 0 // if let views = tabVC.viewControllers { // for tab in views { // tab.tabBarItem.title = names[index] // index = index + 1 // } // } //// self.window?.rootViewController = tabVC //// self.window?.makeKeyAndVisible() // let rootViewController = self.window!.rootViewController as! UINavigationController; //// rootViewController.pushViewController(tabVC, animated: true); //// self.window?.rootViewController = tabVC // // // }
// bottomTitles() ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions )
return true
}
func registerForPushNotifications() {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
} else {
}
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
// 1. Check if permission granted
guard granted else { return }
// 2. Attempt registration for remote notifications on the main thread
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
} else {
let settings = UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let appId: String = Settings.appID!
if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host == "authorize" {
return ApplicationDelegate.shared.application(app, open: url, options: options)
}
return false
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
print("Background")
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
if(self.pref.bool(forKey: "isLoggedin")) {
self.ppnCommandCall()
}
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("Active")
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
AppEvents.activateApp()
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// 1. Convert device token to string
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
// 2. Print device token to use for PNs payloads
// print("Device Token: (token)") pref.set(token, forKey: "deviceToken") print("Device Token ===>", token) }
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register for remote notifications with error: \(error)")
pref.set("No PNS", forKey: "deviceToken")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print(userInfo)
if(self.pref.bool(forKey: "isLoggedin")) {
self.ppnCommandCall()
}
}
func ppnCommandCall() {
if !NetworkState.isConnected() {
print("Internet not available.")
let alertVc = UIAlertController(title: "Alert!", message: "No internet connection. Please turn on internet connection.", preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertVc.addAction(action)
self.window?.rootViewController?.present(alertVc, animated: true, completion: nil)
return
}
let network: NetworkServiceFace = NetworkServiceFace ()
network.PPNCommand {
response in
print("PPNRESPONSE",response)
if response.Status == "Time Out"{
let alertVC = UIAlertController(title: "Notification", message: "Server Time Out" , preferredStyle: .alert)
let alertAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertVC.addAction(alertAction)
self.window?.rootViewController?.present(alertVC, animated: true, completion: nil)
return
}
let value = response.data as! PPNCMDResponseDataModel
self.responsedata = value
if value.STATUS == "True" {
if value.ACTION == "walletsync" || value.ACTION == "mpt"{
NotificationCenter.default.post(name: Notification.Name("PunchRewardIdentifier"), object: nil)
let pop = NewPopUpView()
pop.show(details: value){
(date) -> Void in
if date != nil {
if date == "OK" {
if value.FB_POINTS == "none" {
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
let redViewController = mainStoryBoard.instantiateViewController(withIdentifier: "myTabbarControllerID") as! UITabBarController
let frontVc:UINavigationController = UINavigationController.init(rootViewController: redViewController)
self.window?.rootViewController = frontVc
redViewController.selectedIndex = 1
}else{
// self.tabBarController?.selectedIndex = 1
let rootViewController = self.window!.rootViewController as! UINavigationController
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let profileViewController = mainStoryboard.instantiateViewController(withIdentifier: "RatingViewController") as! RatingViewController
// let profileViewController = mainStoryboard.instantiateViewController(withIdentifier: "PointsPostingViewController") as! PointsPostingViewController profileViewController.responsedata1 = value rootViewController.pushViewController(profileViewController, animated: true) } }else{
self.responsedata = value
self.shareCardOnFaceBook()
}
}
}
} else{
NotificationCenter.default.post(name: Notification.Name("PunchRewardIdentifier"), object: nil )
var msg = ""
if value.ACTION == "callinbox" {
msg = "You have message in your inbox. Please check"
}
let alertVC = UIAlertController(title: "Notification", message: msg , preferredStyle: .alert)
let alertAction = UIAlertAction(title: "Ok", style: .default, handler: {
action in
if value.ACTION.contains("force_update") {
let arr = value.ACTION.split(separator: ";")
let url = arr[1]
print("URL===>", url);
if let url = URL(string: String(url)),
UIApplication.shared.canOpenURL(url){
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
else if value.ACTION == "callinbox" {
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
let redViewController = mainStoryBoard.instantiateViewController(withIdentifier: "myTabbarControllerID") as! UITabBarController
let frontVc:UINavigationController = UINavigationController.init(rootViewController: redViewController)
self.window?.rootViewController = frontVc
redViewController.selectedIndex = 2
}else if value.ACTION == "forcelogout_format" {
let storyBoard: UIStoryboard = UIStoryboard(name:"Main" ,bundle:nil)
let loginVc: UIViewController = storyBoard.instantiateViewController(withIdentifier: "LoginMainViewController")
let frontVc:UINavigationController = UINavigationController.init(rootViewController: loginVc)
self.window?.rootViewController = frontVc
} else if value.ACTION.contains("goto") {
let arr = value.ACTION.split(separator: ";")
let url = arr[1]
print("URL===>", url);
let tab = Int(url)!
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
let redViewController = mainStoryBoard.instantiateViewController(withIdentifier: "myTabbarControllerID") as! UITabBarController
let frontVc:UINavigationController = UINavigationController.init(rootViewController: redViewController)
self.window?.rootViewController = frontVc
redViewController.selectedIndex = tab
}
// } }) alertVC.addAction(alertAction) self.window?.rootViewController?.present(alertVC, animated: true, completion: nil) } } else {
}
}
}
func shareCardOnFaceBook()
{
let galaryarray = responsedata.CARD_URL.components(separatedBy: "->")
let type = galaryarray[1]
if type == "url" {
let shareContent = ShareLinkContent()
shareContent.contentURL = URL(string:galaryarray[0])!
let str = "I have just received \(responsedata.TRANSACTIONTYPE) points from \(responsedata.CARD_TITLE)."
shareContent.quote = str
ShareDialog(fromViewController: self.window?.rootViewController, content: shareContent, delegate: self).show()
// ShareDialog()
}else
{
let url = URL(string:galaryarray[0])
if let data = try? Data(contentsOf: url!)
{
let image: UIImage = UIImage(data: data)!
print(image)
let shareImage = SharePhoto()
shareImage.image = image //Image from your imageview
shareImage.isUserGenerated = true
let content = SharePhotoContent()
content.photos = [shareImage]
let sharedDialoge = ShareDialog()
sharedDialoge.shareContent = content
sharedDialoge.fromViewController = self.window?.rootViewController
sharedDialoge.mode = .automatic
sharedDialoge.delegate = self
if(sharedDialoge.canShow)
{
sharedDialoge.show()
ShareDialog(fromViewController: self.window?.rootViewController, content: content, delegate: self).show()
}
else
{
print("Install Facebook client app to share image")
}
}
}
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation]
)
}
}
private extension AppDelegate {
/// The simplest implementation of Siren.
/// All default rules are implemented and the
/// results of the completion handler are ignored.
/// The simplest implementation of Siren.
/// All default rules are implemented and the
/// results of the completion handler are returned or an error is returned.
}
Are you able to reproduce in a small sample app?
it is solved . updated pods to latest version
Checklist
Environment
Describe your dev environment here, giving as many details as possible. If you have them, make sure to include:
X.X.X
X.X.X
(if issue is Swift related)[Cocoapods|Carthage|Manual]
versionX.X.X
Goals
What do you want to achieve?
Expected Results
What do you expect to happen?
Actual Results
What actually happened? Can you provide a stack trace?
Steps to Reproduce
What are the steps necessary to reproduce this issue?
Code Samples & Details
Please provide a code sample, as well as any additional details, to help us track down the issue. If you can provide a link to a test project that allows us to reproduce the issue, this helps us immensely in both the speed and quality of the fix.
Note: Remember to format your code for readability: