I'm developping app using spotify-iOS-SDK, i have succesfully connect my app to Spotify from Safari, but when i try to connect my app from Spotify App, it doesn't request authorization in spotify app, instead it throw me back to my app after a checkmark icon show in Spotify and it caused crash to my app because the session is null.
This is my code:
var auth = SPTAuth.defaultInstance()!
auth.redirectURL = URL(string: ENV.SPOTIFY_REDIRECT_URL
auth.clientID = ENV.SPOTIFY_CLIENT_ID
auth.requestedScopes = [SPTAuthStreamingScope, SPTAuthPlaylistReadPrivateScope,
SPTAuthPlaylistModifyPublicScope, SPTAuthPlaylistModifyPrivateScope]
if SPTAuth.supportsApplicationAuthentication(){
UIApplication.shared.openURL(auth.spotifyAppAuthenticationURL())
}else{
if UIApplication.shared.openURL(auth.spotifyWebAuthenticationURL()){
if auth.canHandle(auth.redirectURL) {
// To do - build in error handling
}
}
}
I have put spotify-action in my LSApplicationQueriesSchemes. What am i doing wrong here? I saw DemoProject from https://github.com/spotify/ios-sdk
and it worked. It should request authorization right after my app go to Spotify App
You need some code in your AppDelegate that looks like follows:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let auth = SPTAuth()
if auth.canHandle(auth.redirectURL) {
auth.handleAuthCallback(withTriggeredAuthURL: url, callback: { (error, session) in
// Do other things to save session...
return true
}
return false
}
i have resolved my issues, the problem is my Bundle ID in my app is different from my BundleID in my Spotify Dashboard.
https://developer.spotify.com/my-applications
Just match my bundle ID and it worked!
Related
Testing Environment
Facebook SDK : v.11.0.0
Device Model: iPhone X
iOS Version: 14.1
+Expected Result
App events both Standard Events and Custom Events should be record for iOS 14. We've enable AdvertiserTrackingEnabled by Settings.setAdvertiserTrackingEnabled(true). And we've check debug log request saw SDK sent events success.
+ Actual behaviour
Even though we do set Settings.setAdvertiserTrackingEnabled(true) and debug log request success sent event. But it doesn't seem to be recording on dashboard.
I have developed these Facebook SDK for my one of the app for get the app events. In iOS under 14,15,16, everything works well.
These Facebook events appear once your application runs on real device and in that device have already installed facebook app and its login then the events will be appear in event manager otherwise not shows in event manager.
app added into Facebook developer page and get the app id and client token.
added info plist these below lines replace with your App ID and client token
<key>NSUserTrackingUsageDescription</key>
<string>${PRODUCT_NAME} please allow to tracking used to provide you a better and personalized ad experience.</string>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb674454383521423</string>
</array>
</dict>
<key>FacebookAppID</key>
<string>674454383521423</string>
<key>FacebookClientToken</key>
<string>3067e472e89ff8d7c39a18f38d931301</string>
<key>FacebookDisplayName</key>
<string>AppName</string>
Later in AppDelegate just import these two frameworks and added these code in to didFinshlunch method.
import FBSDKCoreKit
import AppTrackingTransparency
ApplicationDelegate.shared.initializeSDK()
Settings.shared.isAdvertiserTrackingEnabled = true
Settings.shared.enableLoggingBehavior(.appEvents)
Settings.shared.isAutoLogAppEventsEnabled = true
Settings.shared.isAdvertiserIDCollectionEnabled = true
Settings.shared.enableLoggingBehavior(.developerErrors)
Settings.shared.enableLoggingBehavior(.cacheErrors)
Settings.shared.enableLoggingBehavior(.uiControlErrors)
NEXT STEP WE NEED ADD THESE FUNCTION
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if (url.scheme?.hasPrefix("fb"))! {
ApplicationDelegate.shared.application(
application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation
)
}
}
Add these transport security permisssion alert in app delegate and call these function on didbecome active method or else didfinsh lunch methos.
func getTrackingPermission() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
Settings.shared.isAutoLogAppEventsEnabled = true
Settings.shared.isAdvertiserTrackingEnabled = true
print("Authorized")
// Now that we are authorized we can get the IDFA
print(ASIdentifierManager.shared().advertisingIdentifier)
case .denied:
Settings.shared.isAutoLogAppEventsEnabled = false
Settings.shared.isAdvertiserTrackingEnabled = false
// Tracking authorization dialog was
// shown and permission is denied
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
print("Not Determined")
case .restricted:
print("Restricted")
#unknown default:
print("Unknown")
}
}
}
}
Last step added these method in appdelegate
func applicationDidBecomeActive(_ application: UIApplication) {
// 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.
//AppUpdater.shared.showUpdate(withConfirmation: false)
if #available(iOS 15.0, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
switch status{
case .authorized:
Settings.shared.isAutoLogAppEventsEnabled = true
Settings.shared.isAdvertiserTrackingEnabled = true
print(ASIdentifierManager.shared().advertisingIdentifier)
break
case .denied:
Settings.shared.isAutoLogAppEventsEnabled = false
Settings.shared.isAdvertiserTrackingEnabled = false
print(ASIdentifierManager.shared().advertisingIdentifier)
default:
break
}
})
}
AppEvents.shared.activateApp()
}
In these way we can write the events
please added these framework in your class and write the event like this
import FBSDKCoreKit
AppEvents.shared.logEvent(AppEvents.Name(FACEBOOK_EVENTS.paymentDone.rawValue))
----event with params like this one----
var fbParams: [AppEvents.ParameterName : AppEvents.ParameterValue] = [:]
fbParams[AppEvents.ParameterName.content] = AppEvents.ParameterValue.init(rawValue: "10")
fbParams[AppEvents.ParameterName.init(rawValue: "number")] = AppEvents.ParameterValue.init(rawValue: "200")
AppEvents.shared.logEvent(AppEvents.Name.purchased, parameters: fbParams)
I'm using Firebase and FirebaseUI in my project. I want to give the user an options to delete his account, but if the user has been in the app longer than 5 minutes I need to reauthenticate again.
I'm not sure how to fill these parameters in the following method:
+ (FIRAuthCredential *)credentialWithProviderID:(NSString *)providerID
accessToken:(NSString *)accessToken;
With the credentials I can call
- (void)reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *) credential
completion:(nullable FIRAuthDataResultCallback) completion
I know the ProviderId from:
Auth.auth().currentUser.providerID
But how do I get the access token?
You can call this function and get the Token!
Swift Code:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
if let refreshedToken = InstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
}
}
I have followed this tutorial to implement a login with custom provider on an Azure mobile app. The backend works perfectly but when I try to login to my new custom controller I'm not able to do it. It's possible to implement it with Xamarin and also with java Android but is no way to do it with Objective C or Swift.
The object MSClient on Microsoft Azure mobile SDK only has two login implementations.
I have tried both but without luck, the callback always returns an empty client.
I also have tried to store the token created by own API use it for login call but without luck again.
Here is my Swift code:
let client = MSClient(applicationURLString: "https://myApp.azurewebsites.net")
client.login(withProvider: "custom", urlScheme: "myApp", parameters: ["username": "pau", "password": "123456"], controller: self, animated: true) {user, error in
print("USER", user)
print("ERROR", error)
}
We found a solution, it's really easy but the msclient documentation is not clear enough. You just need to pass whatever you need (i.e: username,password) as dictionary in token parameter.
Client.msClient.login(withProvider: "auth", token: params, completion: {user, error in
print("USER", user)
print("ERROR", error)
print("USER ID", user?.userId)
print("TOKEN", user?.mobileServiceAuthenticationToken)
if let user: MSUser = user {
guard let username: String = user.userId else { return }
guard let token: String = user.mobileServiceAuthenticationToken else { return }
Client.username = username
Client.msClient.currentUser = user
completion(true)
}else {
completion(false)
}
})
I'm having a hard time trying to figure out how to determine the login type during a resume session using AWS Cognito. My code is based upon the MobileHub sample (below).
I've integrated a name/password mode for user pools (account creation and login) as well as as a Facebook login button which all works perfectly.
I have some logic in my application that needs to behave differently depending on the login type but I can't figure out how to do it.
Anyone done this?
func didFinishLaunching(_ application: UIApplication, withOptions launchOptions: [AnyHashable: Any]?) -> Bool {
print("didFinishLaunching:")
// Register the sign in provider instances with their unique identifier
AWSSignInManager.sharedInstance().register(signInProvider: AWSFacebookSignInProvider.sharedInstance())
AWSIdentityProfileManager.sharedInstance().register(FacebookIdentityProfile.sharedInstance(), forProviderKey: AWSFacebookSignInProvider.sharedInstance().identityProviderName)
AWSSignInManager.sharedInstance().register(signInProvider: AWSCognitoUserPoolsSignInProvider.sharedInstance())
AWSIdentityProfileManager.sharedInstance().register(UserPoolsIdentityProfile.sharedInstance(), forProviderKey: AWSCognitoUserPoolsSignInProvider.sharedInstance().identityProviderName)
setupAPIGateway()
setupS3()
let didFinishLaunching: Bool = AWSSignInManager.sharedInstance().interceptApplication(application, didFinishLaunchingWithOptions: launchOptions)
if (!isInitialized) {
AWSSignInManager.sharedInstance().resumeSession(completionHandler: { (result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
print("didFinishLaunching Result: \(String(describing: result)) AuthState: \(authState) \n Error:\(String(describing: error))")
if authState == .authenticated {
// Facebook or Cognito???
AWSCognitoUserAuthHelper.getCurrentUserAttribute(name: "sub", completionHandler: { (userid) in
// we need to fetch the user
ObjectManager.instance.getUser(userid: userid, completionHandler: { (user) in
ObjectManager.instance.setCurrentUser(user: user)
})
})
}
}) // If you get an EXC_BAD_ACCESS here in iOS Simulator, then do Simulator -> "Reset Content and Settings..."
// This will clear bad auth tokens stored by other apps with the same bundle ID.
isInitialized = true
}
return didFinishLaunching
}
One solution I found was to cast to the different identity profile types such as the following:
let identityManager = AWSIdentityManager.default()
if let fbIdentityProfile = identityManager.identityProfile as? FacebookIdentityProfile {
print("didFinishLaunching - Facebook login")
} else if let upIdentityProfile = identityManager.identityProfile as? UserPoolsIdentityProfile {
print("didFinishLaunching - User Pools login")
}
I can model logic in my application around this. Not sure if there is a cleaner approach using the MobileHub helper classes or AWS APIs but this works.
I have serve apple-app-site-association in my HTTPS root (kumpul.co.id/apple-app-site-association) and the result is passed from https://branch.io/resources/aasa-validator/#resultsbox
I have configured it in my entitlements: applinks:kumpul.co.id
and i have put this function in my Appdelegate.swift:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
NSLog("Check Universal Link")
// 1
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}
print("url: \(url)")
print("component: \(components)")
// 2
if let match = MatchHandler.sharedInstance.items.filter({ $0.path == components.path}).first {
self.presentMatch(match)
return true
}
//3
let webpageUrl = URL(string: "http://www.kumpul.co.id")!
application.openURL(webpageUrl)
return false
}
For the paths, i set "paths": [ "/match/*"] because the links would be kumpul.co.id/match/play_2.html for example
but when i click my link on WhatsApp or Line message, this function doesn't called at all, i can't see the logs when i click the link. What am i doing wrong here ?
Line is not compatible with Universal Links, so that test case is invalid. Your app won't open when a Universal Link is clicked in Line, even if everything is configured perfectly (you need to offer a web preview of the content with a call-to-action button, like this — the same problem exists on Facebook, by the way).
WhatsApp should be working. If your app is not even launching when the link is clicked, you have a configuration issue. You can try walking through some of the troubleshooting steps on this page. If your app is launching, then your configuration is correct and you should verify the logic inside continue userActivity