Unable to download the note attachmet using Evernote IOS SDK - ios

I have integrated the latest evernote ios sdk from github, That support both regular user and also business user. I can able to list the note book and notes without any issues but when i try to download the note attachment its giving me the following error.
Error Domain=ENErrorDomain Code=1 "Missing result: getResourceData
failed: unknown result" UserInfo=0x10dcb15f0
{NSLocalizedDescription=Missing result: getResourceData failed:
unknown result} Skipping field: due to type mismatch
(received:11)
Here the code i have used to download the note attachment.
+ (void)downloadDataWithNoteBook:(ENNotebook *)notebook fromNoteResource:(EDAMResource *)resource
onCompletion:(ZIdResultBlock)block {
ENPreferencesStore *preference = [ENSession sharedSession].preferences;
ENNoteStoreClient *noteStoreClient = [preference objectForKey:[SEEvernoteHelper getTitleForNoteAttachments:resource]];
NSString *str = resource.guid;
NSLog(#"GUID = [%#]", resource.guid);
[noteStoreClient getResourceDataWithGuid:resource.guid success:^(NSData *data) {
if(block) {
block(data, nil);
}
}
failure:^(NSError *error) {
if (block) {
block(nil, error);
}}];
}

Finally i was able to do it!!!
Here is my code:
//select the file that you want to download from evernote
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
isParentNoteBooks = false;
if ([SEEvernoteHelper isNoteBookInstance:[self.datasourceObjects objectAtIndex:indexPath.row]]) {
self.selectedNoteBook = [self.datasourceObjects objectAtIndex:indexPath.row];
[self fetchAttachmentsForNoteBook:[self.datasourceObjects objectAtIndex:indexPath.row]];
// set here if the notebook is business or not.
if ([SEEvernoteHelper isBussinessNoteBook:self.selectedNoteBook]) {
isCurrentNoteBookBusiness = YES;
}
else{
isCurrentNoteBookBusiness = NO;
}
} else {
self.selectedFileNameToDownload = [SEEvernoteHelper getTitleForNoteAttachments:[self.datasourceObjects objectAtIndex:indexPath.row]];
self.selectedResource = [self.datasourceObjects objectAtIndex:indexPath.row];
[self downloadNoteResultObject:self.selectedResource];
}
}
//start the download process
- (void)downloadNoteResultObject:(id)resultObject {
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = kStrDownloadingLabel;
HUD.detailsLabelText = self.selectedFileNameToDownload;
__weak __typeof__(self) weakSelf = self;
[SEEvernoteHelper downloadDataWithNoteBook:self.selectedNoteBook fromNoteResource:resultObject onCompletion:^(id result, NSError *error) {
if (result) {
[NSThread syncOnMain:^{
//save the downloaded data....
[HUD hide:YES];
}];
} else {
[HUD hide:YES];
[NSThread syncOnMain:^{
//error
}];
}
}];
}
//get the download file
+ (void)downloadDataWithNoteBook:(ENNotebook *)notebook fromNoteResource:(EDAMResource *)resource onCompletion:(ZIdResultBlock)block {
ENNoteStoreClient *noteStoreClient = [[ENSession sharedSession] noteStoreForNotebook:notebook];
[noteStoreClient getResourceWithGuid:resource.guid withData:YES withRecognition:NO withAttributes:YES withAlternateDate:NO success:^(EDAMResource *resource) {
if(block) {
block(resource.data.body, nil);
}
} failure:^(NSError *error) {
NSLog(#"Error : %#",error);
if (block) {
block(nil, error);
}
}];
}

Related

How to clear text inside VENToken?

I have used VENTokenField github library for recipients email. Now the user enter the email and its separated by commas(,). Everything works fine. My question is how to clear the text when user press the submit button.
1) http://imgur.com/a/ObbaB
2) http://imgur.com/a/DCusg
#property (strong, nonatomic) NSMutableArray *inviteFriendNames;
self.inviteFriendNames = [[NSMutableArray alloc]init];
#pragma mark - VENTokenFieldDataSource
- (NSString *)tokenField:(VENTokenField *)tokenField titleForTokenAtIndex:(NSUInteger)index
{
if (self.inviteFriendNames.count > index) {
return self.inviteFriendNames[index];
}
return #"";
}
- (NSUInteger)numberOfTokensInTokenField:(VENTokenField *)tokenField
{
return self.inviteFriendNames.count;
}
#pragma mark - VENTokenFieldDelegate
- (void)tokenField:(VENTokenField *)tokenField didEnterText:(NSString *)text
{
if (![self.inviteFriendNames containsObject:text]) {
self.inviteFriendNames = (NSMutableArray*)[self.inviteFriendNames arrayByAddingObject:text];
[self chosenContactsHasChanged];
}
return;
}
- (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index
{
if (self.inviteFriendNames.count > index) {
NSMutableArray *mutable = [self.inviteFriendNames mutableCopy];
[mutable removeObjectAtIndex:index];
self.inviteFriendNames = mutable;
[self chosenContactsHasChanged];
}
self.tokenField.placeholderText = NSLocalizedString(#"Email", nil);
[self chosenContactsHasChanged];
}
- (void)tokenField:(VENTokenField *)tokenField didChangeText:(NSString *)text
{
if ([text hasSuffix:#" "]) {
// Trim off the comma
text = [text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#" "]];
[self tokenField:tokenField didEnterText:text];
} else {
return;
}
}
- (void)updateContactTokenFieldHeightConstraint
{
CGFloat heightOfTokens = self.tokenField.tokenScrollViewHeight + tokenFieldHeightPadding;
CGFloat newHeight = MAX(tokenFieldMinHeight, heightOfTokens);
self.tokenFieldHeight.constant = newHeight;
[self layoutIfNeeded];
}
- (void)chosenContactsHasChanged
{
[self.tokenField reloadData];
[self updateContactTokenFieldHeightConstraint];
}
pragma mark - UIButton Action
-(IBAction)inviteButtonAction:(id)sender{
[self endEditing:YES];
if (self.inviteFriendNames.count == 0) {
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:#"Please enter the mail id." completion:nil];
}else{
NSString *senderName = [NSString stringWithFormat:#"%#.%#",[APPDELEGATE.defaults valueForKey:#"firstName"],[APPDELEGATE.defaults valueForKey:#"lastName"]];
NSDictionary *sendData = #{#"name":senderName,#"emails":inviteFriendNames};
[self.inviteVC sendInviationAPI:INVITE_FRIENDS withParameter:sendData];
}
}
pragma mark - To invitation
-(void)sendInviationAPI:(NSString *)url withParameter:(NSDictionary *)parameters{
// To Check Network Available or Unavailable
if (![PCCommonUtility checkForNetwork]) {
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:[LocalizedStrings warning] description:[LocalizedStrings networkFailure] completion:nil];
}else{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
// To Check Access token is null or empty
if ([APPDELEGATE.defaults valueForKey:CURRENT_TOKEN] && ![[APPDELEGATE.defaults valueForKey:CURRENT_TOKEN]isKindOfClass:[NSNull class]]) {
[PCAPIUtility getResponseFromAPI:url withParameters:parameters withSuccess:^(NSMutableArray *responseData, NSString *success) {
DLog(#"InviteSuccess:%#",responseData);
NSString *status = [NSString stringWithFormat:#"%#",[responseData valueForKey:#"status"]];
NSString *message = [NSString stringWithFormat:#"%#",[responseData valueForKey:#"message"]]
if ([status isEqualToString:#"1"]) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:message completion:^(BOOL confirm) {
if (!confirm) {
[self.inviteView.inviteFriendNames removeAllObjects];
[self.inviteView.tokenField reloadData];
}
}];
}else{
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:message completion:nil];
}
} orFailure:^(NSError *error) {
DLog(#"InviteFailure:%#",error.description);
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:[LocalizedStrings networkFailure] completion:nil];
}];
}else{
NSLog(#"Access Token is Empty");
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}
}
In ViewController class,
.h
#protocol DelegateMethod <NSObject>
-(void)removeArray;
#end
#interface ViewController : UIViewController
#property (nonatomic, strong) id <DelegateMethod> delegate;
#end
.m
-(void)sendInviationAPI:(NSString *)url withParameter:(NSDictionary *)parameters{
// To Check Network Available or Unavailable
if (![PCCommonUtility checkForNetwork]) {
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:[LocalizedStrings warning] description:[LocalizedStrings networkFailure] completion:nil];
}else{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
// To Check Access token is null or empty
if ([APPDELEGATE.defaults valueForKey:CURRENT_TOKEN] && ![[APPDELEGATE.defaults valueForKey:CURRENT_TOKEN]isKindOfClass:[NSNull class]]) {
[PCAPIUtility getResponseFromAPI:url withParameters:parameters withSuccess:^(NSMutableArray *responseData, NSString *success) {
DLog(#"InviteSuccess:%#",responseData);
NSString *status = [NSString stringWithFormat:#"%#",[responseData valueForKey:#"status"]];
NSString *message = [NSString stringWithFormat:#"%#",[responseData valueForKey:#"message"]]
if ([status isEqualToString:#"1"]) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:message completion:^(BOOL confirm) {
if (!confirm) {
[self.delegate removeArray];
}
}];
}else{
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:message completion:nil];
}
} orFailure:^(NSError *error) {
DLog(#"InviteFailure:%#",error.description);
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:[LocalizedStrings networkFailure] completion:nil];
}];
}else{
NSLog(#"Access Token is Empty");
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}
}
In View class
Invite Button Action
-(IBAction)inviteButtonAction:(id)sender{
[self endEditing:YES];
if (self.inviteFriendNames.count == 0) {
[[PCAlertUtility sharedInstance]showOkAlertWithTitle:nil description:#"Please enter the mail id." completion:nil];
}else{
NSString *senderName = [NSString stringWithFormat:#"%#.%#",[APPDELEGATE.defaults valueForKey:#"firstName"],[APPDELEGATE.defaults valueForKey:#"lastName"]];
NSDictionary *sendData = #{#"name":senderName,#"emails":inviteFriendNames};
[self.inviteVC setDelegate:self];
[self.inviteVC sendInviationAPI:INVITE_FRIENDS withParameter:sendData];
}
}
-(void)removeArray {
[self.inviteFriendNames removeAllObjects];
[self.tokenField reloadData];
}

Comparing 2 cities from 2 locations in background

I have an app that the user saves a location and set the radius to be notified about it: 1KM, 5KM (the user will recive a notification if the location he saved earlier and he's current location in in the setted radius) and "City" (the user will recive a notification if the city of the location he saved earlier and the city where he currently is are the same city).
Note: I'm using Google Maps iOS SDK.
I have a method called -sendNotificationIfNeeded that checks if to send a notification, code:
-(void)sendNotificationIfNeeded
{
if (self.muteEnabled==YES) { //Check if the user muted the app
NSLog(#"Mute enabled");
return;
}
//Important part:
if([self checkIfUserInRadiusForLocation:[self.savedLocations objectAtIndex:0]])
{
UILocalNotification *notification=[self createNotification];
[self sendNotification:notification];
}
}
The method checkIfUserInRadiusForLocation check the radius of the savedLocation (CLCircularRegion) and checks if the user is inside this radius, code:
-(BOOL)checkIfUserInRadiusForLocation:(SavedLocation*)location
{
if(location.radiusString isEqualToString:#“1KM”)
{
if(location.circularRegion containsCoordinate:self.locationManager.location.coordinate)
{
return YES;
}
}else if(location.radiusString isEqualToString:#“5KM”)
{
if(location.circularRegion containsCoordinate:self.locationManager.location.coordinate)
{
return YES;
}
//Important part:
}else if(location.radiusString isEqualToString:#“City”)
{
if([self checkIfUserCityIsSameToLocation:location)
{
return YES;
}
}
return NO;
}
The method checkIfUserCityIsSameToLocation: finds the savedLocation city and the user's location city and checks if they're equals (the problem is here), code:
-(BOOL)checkIfUserCityIsSameToLocation:(savedLocation*)location
{
//Checking user's city
__block NSString *userCity;
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:self.locationManager.location.coordinate completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error) {
NSLog(#"%#",[error description]);
}
userCity=[[[response results] firstObject] locality];
}];
//Checking savedLocation’s city
__block NSString *savedLocationCity;
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:location.circularRegion.center completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error) {
NSLog(#"%#",[error description]);
}
savedLocationCity=[[[response results] firstObject] locality];
NSLog(#"");
}];
if ([userCity isEqualToString:savedLocationCity]) { //Both string cities are nil
Return YES;
}else
{
Return No
}
}
The problem is that when the app reaching the if statment on checkIfUserCityIsSameToLocation: both userCity and savedLocationCity are nil (becuase reverseGeocodeCoordinate: completionHandler: method is running on a background thread).
I can't figure out how to solve it,
I'll really appriciate if someone will help me with this.
Thank you very much!
Do it like this:
-(BOOL)checkIfUserInRadiusForLocation:(SavedLocation*)location userCity: (NSString *) userCity locationCity: (NSString *) locationCity
{
if(location.radiusString isEqualToString:#“1KM”)
{
if(location.circularRegion containsCoordinate:self.locationManager.location.coordinate)
{
return YES;
}
}else if(location.radiusString isEqualToString:#“5KM”)
{
if(location.circularRegion containsCoordinate:self.locationManager.location.coordinate)
{
return YES;
}
//Important part:
}else if(location.radiusString isEqualToString:#“City”)
{
if([userCity isEqual: locationCity])
{
return YES;
}
}
return NO;
}
-(void)sendNotificationIfNeeded
{
if (self.muteEnabled==YES) { //Check if the user muted the app
NSLog(#"Mute enabled");
return;
}
SavedLocation* location = [self.savedLocations objectAtIndex:0];
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:self.locationManager.location.coordinate completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error) {
NSLog(#"%#",[error description]);
}
NSString *userCity=[[[response results] firstObject] locality];
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:location.circularRegion.center completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error) {
NSLog(#"%#",[error description]);
}
NSString *savedLocationCity=[[[response results] firstObject] locality];
if([self checkIfUserInRadiusForLocation:location userCity: userCity locationCity: savedLocationCity])
{
UILocalNotification *notification=[self createNotification];
[self sendNotification:notification];
}
}];
}];
}

How to get suggested addresses on some string entered by user using apple's Map?

I am new to iOS. I am using apple's Map. I need some functionality Like goole PlaceAutoComplete.
Before this I was trying to use PlaceAutoComplete By adding googlePlaces utility through pods, and function call back didn't even respond. I have created a iOS Api Key in regards with using googleMap placeAutoComplete utility.
Here is my piece of code
-(void)placeAutocomplete{
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.type = kGMSPlacesAutocompleteTypeFilterCity;
[self.placesClients autocompleteQuery:self.txtFld.text
bounds:nil
filter:filter
callback:^(NSArray *results,NSError*error)
{
if (error != nil) {
NSLog(#"Autocomplete error %#", [error localizedDescription]);
return;
}
self.autoCompleteArray = results;
}];
}
You can get it done either using search bar or making textfield's event textDidChange
I had that done using below code
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(requestForGoogleAutoCompletWithTask) object:nil];
[self performSelector:#selector(requestForGoogleAutoCompletWithTask) withObject:nil afterDelay:0.0];
}
-(void)requestForGoogleAutoCompletWithTask
{
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc]init];
[filter setType:kGMSPlacesAutocompleteTypeFilterNoFilter];
GMSPlacesClient *placesClient = [GMSPlacesClient sharedClient];
[placesClient autocompleteQuery:sBar.text
bounds:nil
filter:filter
callback:^(NSArray *results, NSError *error) {
if (error != nil) {
NSLog(#"Autocomplete error %#", [error localizedDescription]);
arrAutoCompletData = results; // This is my actual array which I am showing in UITableView
[tblView reloadData];
return;
}
arrAutoCompletData = results;
[tblView reloadData];
for (GMSAutocompletePrediction* result in results)
{
NSLog(#"Result '%#' with placeID %#", result.attributedFullText.string, result.placeID);
}
}];
}

share image on twitter and get favourites list from iOS native app

I found many tutorials online how to share image on twitter from an iOS app. But i want to know 2 things about social sharing with twitter-
If i post an image on twitter via my app, Can i get image id from twitter in callback method/block? If yes then how?
If i fetch favourites of a user, is the response include text posted with that image? I checked for the same on twitter Rest API doc that there is a text property returned in the response.
Now my question is that if i post some text with image via my iOS app and later make this post favourite in twitter app and now i get my favourites list through twitter rest API in my app, does the text property in the response is same that i posted with my post?
Edit about #1 above:- from SLComposeViewControllerResult docs i found that completion handler return one of
typedef NS_ENUM (NSInteger,
SLComposeViewControllerResult ) {
SLComposeViewControllerResultCancelled,
SLComposeViewControllerResultDone
};
constant so there is no info about image just posted. Am i right? If not please give me some reference about how to get image id please.
Here I have customize alertView,NSLog,etc. You ignore that.
Here is the code to share to twitter by using STTwitter library
- (void)shareToTwitter
{
APP_DELEGATE.navController = self.navigationController;
NSString *strTwitterToken = [[NSUserDefaults standardUserDefaults] objectForKey:#"TwitterToken"];
NSString *strTwitterTokenSecret = [[NSUserDefaults standardUserDefaults] objectForKey:#"TwitterTokenSecret"];
if (strTwitterToken && strTwitterTokenSecret)
{
self.twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:TwitterConsumerKey consumerSecret:TwitterSecretKey oauthToken:strTwitterToken oauthTokenSecret:strTwitterTokenSecret];
[self.twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
DLogs(#"Twitter User Name");
[self twitterMediaUpload];
} errorBlock:^(NSError *error) {
DLogs(#"-- error: %#", error);
[AppConstant showAutoDismissAlertWithMessage:[error localizedDescription] onView:self.view];
[self safariLoginTwitter];
}];
}
else
{
[self safariLoginTwitter];
}
}
-(void)safariLoginTwitter
{
// [APP_CONSTANT getNativeTwitterAccountAccessToken:^(id result) {
//
// }];
self.twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:TwitterConsumerKey
consumerSecret:TwitterSecretKey];
[self.twitter postTokenRequest:^(NSURL *url, NSString *oauthToken) {
DLogs(#"-- url: %#", url);
DLogs(#"-- oauthToken: %#", oauthToken);
[[UIApplication sharedApplication] openURL:url];
} authenticateInsteadOfAuthorize:NO
forceLogin:#(YES)
screenName:nil
oauthCallback:#"myapp://twitter_access_tokens/"
errorBlock:^(NSError *error) {
DLogs(#"-- error: %#", error);
[AppConstant showAutoDismissAlertWithMessage:[error localizedDescription] onView:self.view];
}];
}
- (void)setOAuthToken:(NSString *)token oauthVerifier:(NSString *)verifier {
[self.twitter postAccessTokenRequestWithPIN:verifier successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName) {
DLogs(#"-- screenName: %#", screenName);
/*
At this point, the user can use the API and you can read his access tokens with:
_twitter.oauthAccessToken;
_twitter.oauthAccessTokenSecret;
You can store these tokens (in user default, or in keychain) so that the user doesn't need to authenticate again on next launches.
Next time, just instanciate STTwitter with the class method:
+[STTwitterAPI twitterAPIWithOAuthConsumerKey:consumerSecret:oauthToken:oauthTokenSecret:]
Don't forget to call the -[STTwitter verifyCredentialsWithSuccessBlock:errorBlock:] after that.
*/
[[NSUserDefaults standardUserDefaults] setObject:self.twitter.oauthAccessToken forKey:#"TwitterToken"];
[[NSUserDefaults standardUserDefaults] setObject:self.twitter.oauthAccessToken forKey:#"TwitterTokenSecret"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self twitterMediaUpload];
} errorBlock:^(NSError *error) {
[AppConstant showAutoDismissAlertWithMessage:[error localizedDescription] onView:self.view];
DLogs(#"-- %#", [error localizedDescription]);
}];
}
-(void)twitterMediaUpload
{
// ProfileImageBO *objProfImg = nil;
//
// if ([self.objProfile.arrUserImages count]) {
// objProfImg = [self.objProfile.arrUserImages objectAtIndex:0];
// }
[APP_CONSTANT showLoaderWithTitle:#"posting" onView:self.view];
// NSURL *urlProfImg = [NSURL URLWithString:[objProfImg.imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *screenshotUrl = [self getScreenshotUrl];
[self.twitter postMediaUpload:screenshotUrl uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
DLogs(#"uploading");
} successBlock:^(NSDictionary *imageDictionary, NSString *mediaID, NSString *size) {
DLogs(#"imageDictionary = %#, mediaID = %#, size %#",imageDictionary.description,mediaID,size);
[self postToTheTwitterWithMediaId:mediaID];
} errorBlock:^(NSError *error) {
DLogs(#"Error in uploading media, try again ...");
[APP_CONSTANT hideLoader];
[AppConstant showAutoDismissAlertWithMessage:error.localizedDescription onView:self.view];
}];
}
-(void)postToTheTwitterWithMediaId:(NSString *)mediaID
{
NSString *msg = [NSString stringWithFormat:#"Check out My Profile"];
[self.twitter postStatusUpdate:msg inReplyToStatusID:nil mediaIDs:[NSArray arrayWithObject:mediaID] latitude:nil longitude:nil placeID:nil displayCoordinates:nil trimUser:nil successBlock:^(NSDictionary *status) {
DLogs(#"Description %#",status.description);
[self showNotificationToastWithMessage:TwitterPostSuccess];
[APP_CONSTANT hideLoader];
} errorBlock:^(NSError *error) {
DLogs(#"Twitter posting error %#",error.description);
[APP_CONSTANT hideLoader];
[AppConstant showAutoDismissAlertWithMessage:error.localizedDescription onView:self.view];
}];
}
For your second question: Yes, you will get the same text in the response
And This is the code to get favorite list
-(void)getFavListTwitter
{
[self.twitter getFavoritesListWithSuccessBlock:^(NSArray *statuses) {
DLogs(#"%#",statuses.description);
} errorBlock:^(NSError *error) {
DLogs(#"%#",error.description);
}];
}

Spotify EXC_BAD_EXE while second time tap on Login Button after dismiss LoginViewController

Hi i Intigrate SpotifyLib CocoaLibSpotify iOS Library 17-20-26-630 into my Project. I open its SPLoginViewController using Bellow Method:-
-(void)OpenSpotify
{
NSError *error = nil;
[SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
userAgent:#"com.mycomp.spotify"
loadingPolicy:SPAsyncLoadingImmediate
error:&error];
if (error != nil) {
NSLog(#"CocoaLibSpotify init failed: %#", error);
abort();
}
[[SPSession sharedSession] setDelegate:self];
[self performSelector:#selector(showLogin) withObject:nil afterDelay:0.0];
}
-(void)showLogin
{
SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]];
controller.allowsCancel = YES;
//controller.view.frame=;
[self presentViewController:controller animated:YES completion:nil];
}
At First time that Appear Spotify Login Screen. After that I tap On Cancel Button, and Try to open again login screen then i got crash EXC_BAD_EXE at this line. sp_error createErrorCode = sp_session_create(&config, &_session);
UPDATE
I Found exet where is got BAD_EXC
in this method
+(void)dispatchToLibSpotifyThread:(dispatch_block_t)block waitUntilDone:(BOOL)wait {
NSLock *waitingLock = nil;
if (wait) waitingLock = [NSLock new];
// Make sure we only queue one thing at a time, and only
// when the runloop is ready for it.
[runloopReadyLock lockWhenCondition:1];
CFRunLoopPerformBlock(libspotify_runloop, kCFRunLoopDefaultMode, ^() {
[waitingLock lock];
if (block) { #autoreleasepool { block(); } }
[waitingLock unlock];
});
if (CFRunLoopIsWaiting(libspotify_runloop)) {
CFRunLoopSourceSignal(libspotify_runloop_source);
CFRunLoopWakeUp(libspotify_runloop);
}
[runloopReadyLock unlock]; // at hear when my debug poin reach after pass this i got bad_exc
if (wait) {
[waitingLock lock];
[waitingLock unlock];
}
}
after doing lots of search i got Solution i check that whether the session already exists then i put if condition like:-
-(void)OpenSpotify
{
SPSession *session = [SPSession sharedSession];
if (!session) {
NSError *error = nil;
[SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size]
userAgent:#"com.mycomp.spotify"
loadingPolicy:SPAsyncLoadingImmediate
error:&error];
if (error != nil) {
NSLog(#"CocoaLibSpotify init failed: %#", error);
abort();
}
[[SPSession sharedSession] setDelegate:self];
}
[self performSelector:#selector(showLogin) withObject:nil afterDelay:0.0];
}
-(void)showLogin
{
SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]];
controller.allowsCancel = YES;
[self presentViewController:controller animated:YES completion:nil];
}
Now no crash and working fine.

Resources