Integrating Chartboost to Swift - ios

I have integrated all the chartboost the from https://answers.chartboost.com/hc/en-us/articles/201220095-iOS-Integration
but I'm keep getting these 18 errors in my chartboost.h file.
http://i.stack.imgur.com/s7Xek.png
I'm not sure if I made my AppDelegate.swift correct to integrate swift?
class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let kChartboostAppID = "559f1b52c909a64f054eb563";
let kChartboostAppSignature = "41ad09b1bd90bbf3b3712d9530f45daff3fbd04f";
Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self)
Chartboost.setShouldRequestInterstitialsInFirstSession(false)
return true
}
func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
{
}
func didDismissInterstitial(location :String! )
{
if(location == CBLocationHomeScreen)
{
Chartboost.cacheInterstitial(CBLocationMainMenu)
}
else if(location == CBLocationMainMenu)
{
Chartboost.cacheInterstitial(CBLocationGameOver)
}
else if(location == CBLocationGameOver)
{
Chartboost.cacheInterstitial(CBLocationLevelComplete)
}
else if(location == CBLocationLevelComplete)
{
Chartboost.cacheInterstitial(CBLocationHomeScreen)
}
}
please help i have been stuck here for a while now please can you help?

I had the same the problem. I brought the entire Chartboost folder into my project instead of just the framework. Go into the folder and delete ChartboostExample. There's an example Xcode project in there that seems to causing weird things to happen.

Related

Why Firebase Remote Config doesn't update values?

I'm using Firebase Remote Config, I have some troubles to update values.
My values are updated only if I close and relaunch the app.
But never if my app enters in foreground.
The developer is activated, with no cache delay.
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
let _ = RCFirebaseValues.sharedInstance
}
}
My Firebase Remote Config class:
enum ValueKey: String {
case force_update
}
class RCFirebaseValues {
static let sharedInstance = RCFirebaseValues()
var loadingDoneCallback: (() -> ())?
var fetchComplete: Bool = false
private init() {
loadDefaultValues()
fetchCloudValues()
}
func loadDefaultValues() {
RemoteConfig.remoteConfig().setDefaults(fromPlist: "RemoteConfigDefaults")
}
func fetchCloudValues() {
#if DEBUG
let expirationDuration: TimeInterval = 0
RemoteConfig.remoteConfig().configSettings = RemoteConfigSettings(developerModeEnabled: true)
#else
let expirationDuration: TimeInterval = 3600
#endif
RemoteConfig.remoteConfig().fetch(withExpirationDuration: expirationDuration) {
[weak self] (status, error) in
guard error == nil else {
DLog(message:"Uh-oh. Got an error fetching remote values \(String(describing: error))")
return
}
RemoteConfig.remoteConfig().activateFetched()
self?.fetchComplete = true
self?.loadingDoneCallback?()
}
}
func bool(forKey key: ValueKey) -> Bool {
return RemoteConfig.remoteConfig()[key.rawValue].boolValue
}
func string(forKey key: ValueKey) -> String {
return RemoteConfig.remoteConfig()[key.rawValue].stringValue ?? ""
}
func double(forKey key: ValueKey) -> Double {
if let numberValue = RemoteConfig.remoteConfig()[key.rawValue].numberValue {
return numberValue.doubleValue
} else {
return 0.0
}
}
}
What's wrong?
EDIT after Mosbah's response:
class AppDelegate: UIResponder, UIApplicationDelegate {
var remoteConfig:RCFirebaseValues!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
self. remoteConfig = RCFirebaseValues.sharedInstance
}
}
Your RCFirebaseValues scope is wrong, it will be nil as soon as you are out of application: didFinishLaunchingWithOptions: so you should keep a strong reference to your object (create a var on AppDelegate).

twitter login swift 4

I want to implement twitter login in my app but i get error.
Class TWTRAppAuthProvider is implemented in both /Users/mohamedeldewaik/Library/Developer/CoreSimulator/Devices/1F7EFA9B-EB86-4E18-8386-284E21A73F92/data/Containers/Bundle/Application/37DD8EB8-2854-44CB-ABAD-3FDADA0FCD1E/alharamin pass.app/Frameworks/TwitterKit.framework/TwitterKit (0x105296548) and /Users/mohamedeldewaik/Library/Developer/CoreSimulator/Devices/1F7EFA9B-EB86-4E18-8386-284E21A73F92/data/Containers/Bundle/Application/37DD8EB8-2854-44CB-ABAD-3FDADA0FCD1E/alharamin pass.app/Frameworks/TwitterCore.framework/TwitterCore (0x10510e370). One of the two will be used. Which one is undefined.
I tried this below code but it crashes
TWTRTwitter.sharedInstance().logIn(completion: { (session, error) in
if (session != nil) {
print("signed in as \(session?.userName)");
} else {
print("error: \(error?.localizedDescription)");
}
})
This is my app delegate
import TwitterKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
TWTRTwitter.sharedInstance().start(withConsumerKey:"XzbZgtanfchiPGRRpII1gu70Z",consumerSecret: "4cNlyYssitGQjoWob4eGnBYeCVP20yVNL9P7w9fI4TzhO4RGKg")
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if TWTRTwitter.sharedInstance().application(app, open: url, options: options) {
return true
}
return true
}
}
so how can i implement twitter without this error i searched more and more for a solution but i don't get a correct answer.
Did you added a callback Url in the dashboard like below
twitterkit-CONSUMERKEY://
Please add a Callback url in your twitter dashboard as below (twitterkit-CONSUMERKEY://)
Twitter Login
buttonLogin = TWTRLogInButton(logInCompletion: { session, error in
if (session != nil) {
print("signed in as \(session!.userName)");
} else {
print("error: \(error!.localizedDescription)");
}
})

Beta Testing, Facebook login, Parse. Some users Facebook information is not getting saved to Parse. Swift

I am in beta testing and so far 5 users have complete success for login and function of the app. However 3 users Facebook information is not getting saved to Parse and the app crashes when they try to move onto the VC that loads the user profile. I don't understand what is happening. Here is my login code it will come across as very amateurish and messy so apologies up front! (Newb but trying)
App delegate:
import UIKit
import Bolts
import Parse
import ParseUI
import FBSDKCoreKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// code in here to check devices just left it out as it was too much information to paste.
}
// parse info and connection
Parse.enableLocalDatastore()
Parse.setApplicationId("",
clientKey: "")
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
PFUser.enableAutomaticUser()
let defaultACL = PFACL();
defaultACL.setPublicReadAccess(true)
PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)
if application.applicationState != UIApplicationState.Background {
let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
var noPushPayload = false;
if let options = launchOptions {
noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil;
}
if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
}
}
if application.respondsToSelector("registerUserNotificationSettings:") {
let userNotificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types: UIRemoteNotificationType = [UIRemoteNotificationType.Badge, UIRemoteNotificationType.Alert, UIRemoteNotificationType.Sound]
application.registerForRemoteNotificationTypes(types)
}
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
if succeeded {
print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.");
} else {
print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %#.", error)
}
}
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error.code == 3010 {
print("Push notifications are not supported in the iOS Simulator.")
} else {
print("application:didFailToRegisterForRemoteNotificationsWithError: %#", error)
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Inactive {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
}
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
}
View contorller:
import UIKit
import Parse
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
import ParseUI
class LoginViewController: UIViewController {
var firstName: String!
var lastName: String!
#IBAction func logInWithFacebook(sender: AnyObject) {
let permissions = ["public_profile", "email"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, block: {
(user: PFUser?, error: NSError?) -> Void in
if let error = error {
print(error)
} else {
// user successfully signed in:
if let user = user {
self.performSegueWithIdentifier("registerFacebookSegue", sender: self)
}
}
})
}
override func viewDidAppear(animated: Bool) {
//to log user out
// PFUser.logOut()
// segue if user is logged in:
if let username = PFUser.currentUser()?.username {
self.performSegueWithIdentifier("loggedInProfileSegue", sender: self)
}
}
override func viewDidLoad() {
super.viewDidLoad()
if(FBSDKAccessToken.currentAccessToken() != nil) {
print("user logged in")
} else {
print("user not logged in")
}
}
override func prefersStatusBarHidden() -> Bool {
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Got facebook passwords from a user that wasn't working and tried to log in with xcode and phone connected got this error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
* First throw call stack:
(0x183608f48 0x1980cbf80 0x183608e90 0x1000e49a8 0x1000e8e98 0x10012d344 0x1000e8eec 0x100062ec8 0x1000976f4 0x10009e1c0 0x10009df90 0x10009da44 0x1834ff990 0x1834ff800 0x10009d800 0x10009cd00 0x10009aed4 0x100097eb8 0x100097e10 0x100098288 0x182e9b6a8 0x182e9b638 0x182e9b7ac 0x182d074fc 0x182df5b38 0x101461c68 0x10146b40c 0x182cf3ce4 0x1834ec6cc 0x182cf3bc8 0x182cf3a88 0x182cf38b4 0x1835c0544 0x1835bffd8 0x1835bdcd8 0x1834ecca0 0x18e728088 0x188c04ffc 0x10006e488 0x19891a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The problem was that I was asking for email in my requests and not all facebook accounts have a. a valid email addresses and b. any email address linked at all. So I had to remove this request and ask the user to input their email address separately.

Parse app not working on real device "clang: error: linker command failed with exit code 1" Swift 2.0 Xcode 7 beta 6

I have downloaded the parse core quick start swift Xcode project. It runs perfectly fine in the simulator: I can create users, upload data, etc... But when I try to run it on my physical device I get this error in Xcode: clang: error: linker command failed with exit code 1 (use -v to see invocation) I am sure that I have all the needed library's because the project is strait from parse.com. FWI I'm on Swift 2 Xcode 7 beta 6. I don't think that it's an error in the code but here is my app delegate:
import UIKit
import Bolts
import Parse
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.enableLocalDatastore()
Parse.setApplicationId("XXXXXXXXXXXXXXXXXXXXXXXXXX",
clientKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
PFUser.enableAutomaticUser()
let defaultACL = PFACL();
defaultACL.setPublicReadAccess(true)
PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
if succeeded {
print("good");
} else {
print("bad", error)
}
}
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error.code == 3010 {
print("Push notifications are not supported in the iOS Simulator.")
} else {
print("application:didFailToRegisterForRemoteNotificationsWithError: %#", error)
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Inactive {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
}
}
And my ViewController.swift:
import UIKit
import Parse
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let testObject = PFObject(className: "TestObject")
testObject["foo"] = "bar"
testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
print("Object has been saved.")
}
}
}
See if deleting your derived data folder fixes it.
Also, you may want to change your Parse keys, since you just posted them on StackOverflow.

Chartboost delegate error

I am integrating chartboost into my sprite kit game and have successfully integrated bridging files into my swift code. Now in my app delegate I have the following:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let kChartboostAppID = "5554c8680d60255c6a0f4af4"
let kChartboostAppSignature = "1d0e271cd054c9a63473d2f1212ca33a2922a19f"
Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self)
Chartboost.cacheMoreApps(CBLocationHomeScreen)
return true
}
class func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location: String!, withError error: CBLoadError) {
}
the startWithId line gives me an error that it cant invoke this method with these arguments ( String, String, AppDelegate). This used to work fine on my objective c code.. Anyone knows how to fix this?
class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate
Edit (from Lalit's comment below)
In startWithAppId the delegate is set to self, so you have to set the class AppDelegate as the delegate, which is done using:
ChartboostDelegate(protocol)

Resources