How to logout a user using Box V2 iOS SDK - ios

In the V1 iOS SDK it was possible to logout the current user as follows:
[Box logoutWithCallbacks:^(id <BoxOperationCallbacks> on)
{
on.after(^(BoxCallbackResponse response)
{
});
}];
How is it done using the V2 SDK?

Here's what I do:
BoxSDK *sdk = ... // a reference to the BoxSDK for the user
sdk.OAuth2Session.accessToken = #"INVALID_TOKEN";
sdk.OAuth2Session.refreshToken = #"INVALID_TOKEN";
That's it. The next time you try to do anything with the user's session you will be forced to log in again.
Update - you can see this in action in the Box sample app at https://github.com/box/box-ios-sdk-sample-app. Look at the BoxFolderViewController.m file.

This is how to logout correctly
[BoxSDK sharedSDK].OAuth2Session.accessToken = nil;
[BoxSDK sharedSDK].OAuth2Session.refreshToken = nil;

This is how it's done with the latest SDK from https://github.com/box/box-ios-sdk
[BOXContentClient logOutAll];

swift version answer for logout box sdk session
*
boxClient.destroy { (res) in
}
boxClient = nil

Related

How to get initial link for iOS using react native firebase dynamic links?

I am using react-native-firebase:: 5.6.0, I am having issue while getting initial link for iOS device. On android it's working fine. I am using "Firebase Dynamic Links" to redirect user inside login screen of my app if in case he is not logged in inside app, otherwise just opening app if he is already logged in.
It's working for android app but having an issue with ios app. I have used two function one is the get dynamic link if app is closed "getInitialLink" and another one is to check when app is opened "onLink".
This is function I am using after closing splash screen, only called once when opening app from closing state.
firebase.links().getInitialLink().then((url) => {
if (url && url === 'https://mycustomdomain.co.in') {
navigationToScreen(AUTH, INITIAL_SCREEN);
} else {
// INITIALIZE APP HERE
}
});
If app already opened I am getting dynamic link url value inside this function::
this.unsubscribeHandleOpenAppDynamicLinks = firebase.links().onLink(async (url) => {
let isLoggedIn = await AsyncStorage.getItem(LocalStorageKeys.IS_LOGGEDIN);
if (url) {
if ( isLoggedIn !== 'yes' && url === 'https://mycustomdomain.co.in') {
navigationToScreen(AUTH, INITIAL_SCREEN);
}
}
});
and clearing that listener on componentWillUnmount:: this.unsubscribeHandleOpenAppDynamicLinks();
In case of iOS only "onLink" function is working and I am
getting url value as "undefined". getInitialLink() function will
returns the URL that the app has been launched from. If the app was
not launched from a URL the return value will be null, but I am
getting "undefined" even when launching an app from url in case of iOS
only. I am getting url inside onLink() in case of iOS when app is
launched. Why this is happening??
Please suggest what I am doing wrong here.
If getInitialLink method does not work, it is either because of improper linking or due to Expo runtime. As an alternative, use Linking.getInitialURL method to get the initial URL. This requires a little bit of native code as well. This is because Linking module does not know how to interpret the shortened URL. So, we call the resolveShortLink method of Firebase SDK to get the embedded deep link. Once we receive the embedded deep link, we can handle it as usual in our app.
The native source code is documented in this article. But for completeness, I will post it here.
#import "FDLResolver.h"
#import <React/RCTLog.h>
#implementation FDLResolver
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(resolveShortLink:(NSString *)shortLink :(RCTPromiseResolveBlock)resolve
:(RCTPromiseRejectBlock)reject)
{
id completion = ^(NSURL *_Nullable dynamicLink, NSError *_Nullable error) {
if (!error && dynamicLink) {
resolve(dynamicLink.absoluteString);
} else {
reject(#"Error", #"Error in getting dynamic link", error);
}
};
NSURL *shortLinkURL = [NSURL URLWithString:shortLink];
[[FIRDynamicLinks dynamicLinks] resolveShortLink:shortLinkURL completion:completion];
}
#end
And Linking module code is below.
Linking.getInitialURL().then(url => {
if (url && url.includes('page.link')) {
const shortLink = url.replace('exps', 'https')
NativeModules.FDLResolver.resolveShortLink(shortLink)
.then(link => {
const linkParts = link.split('?')
const query = qs.parse(linkParts[1])
this.parseRouteUrl(query.deep_link_id)
})
}
})

How to open salesforce login screen within the app

I am using salesforce oauth connected app setup. When I launch the app it redirects me to login in the safari in app browser. How to control this? Do I need to use any salesforce library like zksforce.
I followed these steps to create a project: https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/ios_new_force_project.htm
Please suggest me which is the right way to display login screen in a native app.
There is no way to open login screen native -as far as I know :)-
You should set properties first as :
[SalesforceSDKManager sharedManager].connectedAppId = RemoteAccessConsumerKey;
[SalesforceSDKManager sharedManager].connectedAppCallbackUri = OAuthRedirectURI;
[SalesforceSDKManager sharedManager].authScopes = #[ #"web", #"api" ];
you can set callback properties if necessary :
[SalesforceSDKManager sharedManager].postLaunchAction = ^(SFSDKLaunchAction launchActionList) {
};
[SalesforceSDKManager sharedManager].launchErrorAction = ^(NSError *error, SFSDKLaunchAction launchActionList) {
};
And Then you should call :
[[SalesforceSDKManager sharedManager] launch];

Why does FBSDKAccessToken.currentAccessToken() returns nil on my device but works fine in the iOS simulator?

In my IOS9 application I use the Facebook SDK 4.7.0 graph api to search for public places.
I use the FBSDKApplicationDelegate in my apps delegate which I believe provides me with valid app access token (since I don't use any user specific data an application login is sufficient for me).
When I call FBSDKAccessToken.currentAccessToken() in my ViewController to check if the token is valid I always succeed in the simulator but not when deployed on the real device.
Any suggestions?
I have followed the new ios9 guide and provided the additional info in my plist.
Since my application is still in development my Facebook companion app (which holds my app id and secret) are still not available for general public. Could this be a problem?
for checking facebook permission..& give a permission...if permission exist then automatically get accesstoken other wise ask for login...
For Swift
var login: FBSDKLoginManager = FBSDKLoginManager()
login.logInWithReadPermissions(["public_profile", "email"], handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if (error != nil)
{
//Process error
}
else if result.isCancelled
{
//Handle cancellations
}
else
{
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("email"){
//Do work
}
}
})
For Objective c:
check Permission like this. following code use ..
if ([[FBSDKAccessToken currentAccessToken]hasGranted:#"email"])
{
// add your coding here after login call this block automatically.
}
else
{
//login code **//if accesstoken expired...then call this block**
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:#[#"public_profile", #"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
}];
}

removeTracksFromPlaylist not removing tracks with ios spotify sdk

I was testing this method to remove tracks from a playlist. Basically I modified the demo project "simple track playback" provided with the SDK. I wanted to remove the track form the playlist when you hit fastForward. I changed the fastForward method this way but it's not doing anything, and error is nil.
-(IBAction)fastForward:(id)sender {
if([self.player isPlaying] && self.currentPlaylistSnapshot){
SPTAuth *auth = [SPTAuth defaultInstance];
[self.currentPlaylistSnapshot removeTracksFromPlaylist:#[self.player.currentTrackURI]
withAccessToken:auth.session.accessToken
callback:^(NSError *error) {
if (error != nil) {
NSLog(#"*** Failed to remove track : %#", self.titleLabel.text);
return;
}
}];
}
[self.player skipNext:nil];
}
self.currentPlaylistSnapshot is the one I've got from the handleNewSession method.
There's also a static method apparently offering something similar which I have't tried yet.
createRequestForRemovingTracks:fromPlaylist:withAccessToken:snapshot:error:
According to the documentation both options are implemented asynchronously and will take seconds to reflect the results in the server but I'm suspecting that there's either something wrong or I'm just missing to do an actual request to push the changes on the local snapshot maybe?
Documentation:
https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTPlaylistSnapshot.html#//api/name/removeTracksWithPositionsFromPlaylist:withAccessToken:callback:
ios sdk:
https://github.com/spotify/ios-sdk
I solved my issue by reseting simulator + adding SPTAuthPlaylistModifyPublicScope (which I fogot to do...)
auth.requestedScopes = #[SPTAuthStreamingScope, SPTAuthPlaylistModifyPublicScope];

Cordova iOS with Spotify iOS SDK - Trigger Auth

I'm just developing Web Apps based on Cordova, but I have a problem: I want to include Spotify in a new App.
Spotify has the iOS SDK (beta) with a beginner Tutorial. That worked fine (On App load Start the Auth).
Now I would like to implement that in my WebApp using Cordova.exec(); (Not on load - I would like to Auth on Button Click (Triggered by JavaScript).
I've generated a Cordova Plugin for that - that worked. And i can trigger a Method via Cordova.exec();.
This Method get triggered:
- (BOOL)startSpotifyAuth:(CDVInvokedUrlCommand*)command {
// Create SPTAuth instance; create login URL and open it
NSURL *loginURL = [[SPTAuth defaultInstance] loginURLForClientId:kClientId declaredRedirectURL:[NSURL URLWithString:kCallbackURL] scopes:#[#"login"]];
// Opening a URL in Safari close to application launch may trigger an iOS bug, so we wait a bit before doing so.
// [UIApplication performSelector:#selector(openURL:) withObject:loginURL afterDelay:0.1];
NSLog(#"*** GOT THIS IN DEBUG CONSOLE ***");
// Ask SPTAuth if the URL given is a Spotify authentication callback
if ([[SPTAuth defaultInstance] canHandleURL:loginURL withDeclaredRedirectURL:[NSURL URLWithString:kCallbackURL]]) {
NSLog(#"*** GOT THIS - NOT - IN DEBUG CONSOLE ***");
// Call the token swap service to get a logged in session
[[SPTAuth defaultInstance] handleAuthCallbackWithTriggeredAuthURL:loginURL tokenSwapServiceEndpointAtURL:[NSURL URLWithString:kTokenSwapURL] callback:^(NSError *error, SPTSession *session)
{
if (error != nil) {
NSLog(#"*** Auth error: %#", error);
return;
}
// Call the -playUsingSession: method to play a track
[self playUsingSession:session];
}];
return YES;
}
return NO;
}
As you can see by the Debug Outputs: I did not get inside the if(). But I don't know why: The loginURL looks correct.
You're using the wrong URL in your if statement. At that point, you need to validate the URL that gets handed to your application after the user has been bounced out to Safari for authentication, NOT the one you generate using SPAuth.
Are you still having issues with your project? Maybe my Spotify iOS SDK plugin can help. I just published the first version to the plugin registry.
You can install the plugin via the cordova command line client: cordova plugin add com.timflapper.spotify.
Add the ios platform if you haven't already done so: cordova platform add ios.
The following code is a simple example of how to authenticate with Spotify and play a single track:
var session, player;
var urlScheme = 'your-custom-url-scheme';
var clientId = 'your-own-client-id';
function onDeviceReady() {
spotify.authenticate(urlScheme, clientId, 'token', authDone);
}
function authDone(error, sess) {
if (error) return console.log("ERROR!", error);
console.log(sess);
session = sess;
player = spotify.createAudioPlayer(clientId);
player.login(session, function(error) {
if (error) return console.log(error);
player.play('spotify:track:2DlfLPbXH5ncf56Nytxd4w', function(error) {
if (error) return console.log(error);
});
});
}
document.addEventListener('deviceready', onDeviceReady, false);

Resources