cocoa: how to create new SBElementArray? - cocoa

I'm making a application which read emails in Mail.app. Firstly, the application get all senders from Mail.app using
NSArray *emailSenders = [self.mailBox.messages arrayByApplyingSelector:#selector(sender)];
I have to display target user email content, e.g. only show all mails from "abc#gmail.com", so I get the sender indexes which contain the target user email
[emailSenders enumerateObjectsUsingBlock:^(NSString *emailSender, NSUInteger idx, BOOL *stop) {
if([emailSender rangeOfString:userEmail].location != NSNotFound){
[emails addObject:[self.mailBox.messages objectAtIndex:idx]];
}
}];
emails is a SBElementArray created by
SBElementArray *emails = [[SBElementArray alloc]init];
I want to fetch all contents in emails by sending Apple Script Event only once, like
[mails arrayByApplyingSelector:#selector(content)];
so I create my own SBElementArray, but the problem is Xcode display:*** -[SBElementArray init]: should never be used.
when I run this code, how to fix it?

Just add your filtered items to an NSArray or NSMutableArray, and remember that its elements are SBObjects.

Related

What API is there for selecting iTunes library location?

How does one programatically set the iTunes library location on macOS to custom locations using e.g. C / Obj-C or Swift API?
Alternatively, environmental settings, such as modifying plists, using the defaults CLI tool, or similar approaches, are also OK for me.
Ordinarily, selecting a custom iTunes library location is done by launching iTunes while holding down the option key. I need to be able to do this in e.g. a unit testing environment / programatically.
You may be able to set it via the prefs.
This is how I access it.
-(void)loadITunesPrefLibraryPath {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSDictionary *userPref = [userDefaults persistentDomainForName:#"com.apple.iTunes"];
id dataBaseLoc = [userPref objectForKey:#"Database Location"];
NSLog(#"%s dataBaseLoc is:%#", __PRETTY_FUNCTION__, dataBaseLoc);
NSLog(#"%s dataBaseLoc class is:%#", __PRETTY_FUNCTION__, [dataBaseLoc class]);
NSData* dataBaseData = (NSData*)dataBaseLoc;
BOOL staleBook = NO;
NSError* bookError = nil;
NSURL* dataBaseURL = [NSURL URLByResolvingBookmarkData:dataBaseData options:NSURLBookmarkResolutionWithoutMounting relativeToURL:nil bookmarkDataIsStale:&staleBook error:&bookError];
self.libExtDBfile = dataBaseURL;
}
Once you get the userPrefs for iTunes.
And create a BookMarkData from URL.
You might be able to set it via
[userPref setObject:newDataBaseLoc forKey:#"Database Location"];
also see next answer for possible ITLibrary framework private API access

Compare UITextField with PFQuery of parse.com

I have a small problem .. I hope you can help me ...
In my app I'm using Parse.com for data management.
I have a ViewController that contains a TextField called "Email".
With a query parse.com call all the registered user app and their email. Now I would like to try to compare the values of the textField and those of the query .. Let me give an example ..
The user enters their email in the textField but if this email is already present in the archive of the users (of course taken by the query parse.com) shows an alert that warns him that the Supplied in textField is already existing in parse.com.
I tried to do this but it does not always recognize the email in query..dove am I doing wrong?
P.S. the textField is not in viewController Main but is in another
ViewController called generalData.
-(void)query {
PFQuery *totalUser = [PFUser query];
[totalUser findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
[array addObject:object];
NSLog(#"%#", [object objectForKey:NPUserKey_EMAIL]);
// NSStrings
email = generalData.emailTextField.text;
compareEmail = [object objectForKey:NPUserKey_EMAIL];
}
}
}];
}
- (IBAction)presentNextViewController:(id)sender {
if ([generalData.emailTextField.text isEqualToString:compareEmail]) {
NSString *stringError = [NSString stringWithFormat:#"L'email %# รจ gia presente nei nostri archivi.",email];
NPUMessageView *alertMessage;
alertMessage= [[NPUMessageView alloc] showViewWithMessage:stringError withBackgroundColor:SECONDARY_COLOR];
[self.view addSubview:alertMessage];
[alertMessage showAnimatedView];
NSLog(#"email found in archive");
}
else {
NSInteger index = [controllersContainer indexOfObject:self.destinationViewController];
index = MIN(index+1, [controllersContainer count]-1);
[self presentCurrentViewController:self.currentViewController withPage:index];
}
}
I think you are getting ahead of yourself a little bit. Parse automatically checks for duplicate emails when you try to sign up a new user. Let the user enter their email into the field, and when they try to create the account, display the error Parse returns from the signup method, and let them try again!
https://www.parse.com/docs/ios_guide#users-signup/iOS

Accessing 'Internet Accounts' programmatically

I'm trying to access the 'accounts' that are stored in the Internet Accounts area on the system settings on OSX. I'm aware of the 'ACAccount' library, but this only really seems to be of any use for Social integration, for example Facebook/Twitter, what i would like is to be able to detect that you have an Exchange account there and open up certain features within an app. But i'm guessing i'll need to get my users to re-enter their details in my app?
I did try and use it, however i get an empty array.
ACAccountStore *store = [[ACAccountStore alloc] init];
NSArray *accounts = [store accounts]; //This is empty
Does anyone know if i'm missing something, or if it's not possible? Thanks!
Edit
I have gained access to the Twitter account for example, but it's not returned in the Accounts list, i had to request permission first. Which makes sense. However, i still see no way of getting access to the Exchange account.
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSArray *arrayOfAccounts = [account
accountsWithAccountType:accountType];
}
}];

Need a solution to implement xmpp add friends in group chat and sending message to them in once in ios

I'm having difficulties to add friends, sending invitations and also in group chat like sending one message for all using xmpp. i know that I need to use XEP-0045. But I am not succeeded. Can anybody tell me how to do it.
Send friend request for one to one chat.
send invitation to join chat room.
send message to chat room's friends.
if somebody has sample code that would be great..
Thanks in advance
for #3 : send message to chat room's friends.
-(void) sendGroupMessage:(NSString *) groupJID Message:(NSString *)msg{
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:#"%##conference.%#",groupJID,SERVER_URL]];
XMPPRoom *muc = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[muc activate:xmppStream];
[muc addDelegate:self delegateQueue:dispatch_get_main_queue()];
[muc sendMessageWithBody:msg];
}
Point 2: Send invitation to join chat room.
You can send invitation to others when you get the response in following delegate (xmppRoomDidCreate):
- (void)xmppRoomDidCreate:(XMPPRoom *)xmppRoom
{
NSLog(#"xmppRoomDidCreate");
[xmppRoom inviteUser:[User JID Here] withMessage:#"Your Message Here"];
// You can send invitations in loop if you have multiple users to invite
}
Point 3: Send message to chat room's friends.
Actually the message is broadcasted in group. Surely shall be delivered to all members in group.
- (void) sendMessageInGroup:(NSString *) message withGroupName:(NSString *) groupName
{
NSString * qualifiedGroupName = [NSString stringWithFormat:#"%##%#", [groupName lowercaseString], SERVER_NAME];
// self.xmppRoomDetails consists of your muc rooms' objects i.i XMPPRoom
for (int i = 0; i < self.xmppRoomDetails.count; i++)
{
XMPPRoom * room = [self.xmppRoomDetails objectAtIndex:i];
XMPPJID * myRoomJID = room.myRoomJID;
NSString * roomName = [NSString stringWithFormat:#"%##%#", [myRoomJID.user lowercaseString], SERVER_NAME];
if ([qualifiedGroupName rangeOfString:roomName].location != NSNotFound)
{
XMPPRoom * sendMessageWithRoom = [self.xmppRoomDetails objectAtIndex:i];
[sendMessageWithRoom sendMessage:message];
}
}
}

Xcode: getting badge value to add it to a label

I have an app that receives push notification.
I would like to add the badge with the right value near a button inside the application menu (do you remember the old Facebook app?).
I'm trying to get the badge value from the notification in the AppDelegate, save it in NSUserDefault to use it in other view controllers.
NSString * badgeValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:badgeValue forKey:#"badge"];
[defaults synchronize];
The problem is that if I try to put the value in a label the app crashes
'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance
Xcode makes me save badgeValue in a string but when I put the string in the label it says is not a proper string
if ([badgeValue isKindOfClass:[NSString class]]) {
NSLog(#"it is string !!!!!!!!!!!!!!!");
// treat it as a string object
} else {
NSLog(#"it is not a string !!!!!!!!!!!!!!!");
// treat it as a number object
}
By debugging I see that badgeValue is not a real string but __NSCFNumber and if I try to convert it in a string the return value is a long strange number.
I searched everywhere for a way to get the badge value of the notification but the only option I can think of is a php query...Any idea?
What do you mean by "Xcode makes me save badgeValue in a string"? Do you get an error or a compiler warning if you try to type badgeValue as an NSNumber? The documentation and your own logging tell you that the value of the key "badge" is an NSNumber.
NSNumber * badgeValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
[label1 setIntValue:badgeNumber.intValue];
Does something like this not work?
Yes, Just yesterday I tried with
NSString *string = [NSString stringWithFormat:#"%d", [badgeValue intValue]];
And it works! Thanks for help

Resources