Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 28    Views: 85

Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
03/15/14 09:51 AM (10 years ago)

Setting Sms message data

Hey guys, I am trying to set a 'sendsms' screen with a few changes. I want the content of the sms ("textMessage":"message content here") to grab the data from another plugins json data. Is that possible? Hope so, Thanks, Jeremy
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
03/15/14 10:49 AM (10 years ago)
It most certainly is possible. In Android / Java, use BT_strings.setPrefString("textMessage", "some string"); to set the value of a variable in one plugin / class, and then use String someString = BT_strings.getPrefString("textMessage") to take it out in another class.
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 10:50 AM (10 years ago)
Know how id do it in iOS? Thanks Jeremy
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 11:03 AM (10 years ago)
if it helps, here is the sendsms bit i want to change. //set message body if([theScreenData.jsonVars objectForKey:@"textmessage"]){ [picker setBody:[theScreenData.jsonVars objectForKey:@"textMessage"]]; } And i want to use it to get the data from smugs message location plugin. I need the message content to be the users location. (if you are familiar at all with the plugin you know what i want.)
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
03/15/14 11:05 AM (10 years ago)
Not everybody has that plugin. Have you asked Smug directly?
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 11:09 AM (10 years ago)
Yeah i messaged him, but i have been trying and wondered if anyone may have needed to do this. I know not everyone has it, but i meant if your familiar with it you have it so you'd know that i want the users location data to be sent. Thanks, Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 03:37 PM (10 years ago)
It may be because I'm still a bit sleepy. I can see you wanting to do something that looks like it can be done… but I'm not 100% sure of what it is… Recipients of both email and sms are arrays, so if you want one or 100 numbers, it can be done… just keep adding numbers in the array. This requires the user to enter a number: picker.recipients = [NSArray arrayWithObjects: nil, nil, nil]; this does not: picker.recipients = [NSArray arrayWithObjects:@“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, @“12345678”, @“87654321”, nil]; The URL Data that is usually in the body of the message is merely current coordinates and some text. You can create that 'on the fly' if you want. Just use whatever text you want (like the URL) and grab the device lat/lng for your values… Does that make sense? Cheers! -- Smug PS, I never answer messages before I wake up. I've tried before, but it doesn't work out so well ;)
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 03:41 PM (10 years ago)
So in my app there's 7 screens in question. Each one is for a different store branch the location needs to be messaged to. So if on screen one number goes to xxxxxxx1 If on screen two number goes to xxxxxxx2. Feel me? Thanks, Jeremy. Ps I find it hard to believe you don't reply to messages whilst sleeping. If you did you wouldn't have to get up so early! Lol
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 03:56 PM (10 years ago)
What kind of screens would they be? Could each screen have a little SMS code for it? Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 04:47 PM (10 years ago)
I just have: >7 screens (menu with image) >>Each menu has: >>>Call screen >>>msgLocation each of the 7 screens is for a business. each business has a different number. so depending one the user is on it needs to go to the respective ones number. Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 05:47 PM (10 years ago)
Ahhhhhhh…. I gotcha. You want 'pre-entered' numbers/messages for each location. Each location has a MWI menu that has two entries per location; one 'call', one msg loc. You can't 'pre-enter' the number in the code, because the code affects ALL Screens. Got it. If this is the case, you may want to add some code in to determine the screen/location and have it 'autoselect' the correct number/location/message based on the screen ID, or screen nickname. Something like: NSString *testLoc = [screenData.jsonVars objectForKey:@"itemNickname"]; if ([testLoc isEqualToString:@"location_one"]) { picker.recipients = [NSArray arrayWithObjects: @"202-456-1111", nil, nil]; } else if ([testLoc isEqualToString:@"location_two"]) { picker.recipients = [NSArray arrayWithObjects: @"202-456-1112", nil, nil]; } else if ([testLoc isEqualToString:@"location_three"]) { // this could go on forever } You can't use a 'switch' statement unless you create a numerical representation for each screen… a bit over the top for this. But this albiet ugly should work fine. Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 05:52 PM (10 years ago)
Ah i love it when i manage to explain something enough to get it understood :D Thats it exactly. Now, using this, can i future proof and add the if statements for from location_one through to location_50 so i need only update the app when i have filled the first 50 locations? I find this 'ugly' code beautiful because i understand it completely...almost. "location one would be the screen name? Thanks! Jeremy
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 05:54 PM (10 years ago)
and also, what is with the 'nil, nil' 's after the number?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 06:19 PM (10 years ago)
You can 'future' proof, providing you can predict the future, and that the future doesn't change, lol! I used 'itemNickname' as an example. It can be used, as well as 'ItemId', or 'navBarTitleText'; any of your included JSON values as long as they are unique to each screen. The 'nil, nil' is the default information. Honestly not sure if they're needed or not; It was in the original example I found, and every example I've seen since uses them. Not sure why they're there, not sure what can happen if they're not included. I just kept up with the status quo. If you remove them and it doesn't work; add them back ;) Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 06:23 PM (10 years ago)
Oki. Future proofing...not yet. So it would be the itemid or navbar title text etc of your message location plugin in question yeah? Well i added extra nils and took some away and it still worked. But i also like to conform and will let them live on. Thanks, Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 06:34 PM (10 years ago)
yes; the title text of the MsgLoc in question. or NavBar text. If you 'really' want to future proof, you 'could' add additional values in your data, and customize the plugin to accomodate for it. Consider this: In each BTv3 plugin, we have the ability to manually augment or change the json data, via the JSON Configuration Data (Editable) that resides in each new BTv3 plugin. You can 'add' json particular to your location in THERE, providing YOU remember to add the required info with each new screen… You won't need to 're-release' because the core code is already in the project… For instance, today you have 7, tomorrow you may have 700. no problem. Just add two new Json key/value sets to each screen: "locationPhone":"212-123-4567", "locationName":"Joe's Tavern" be sure to make certain it's all the 'correct' json (commas, quote marks, etc…) then, in the code, trigger on 'locationName' and insert 'locationPhone'. It's a little manual effort, but the long term benefits are there. Cheers! -- Smug
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 06:37 PM (10 years ago)
NSString *myNum = [screenData.jsonVars objectForKey:@"locationPhone"]; if (myNum.length < 1) myNum = nil; // in case there is no number, you don't want an error picker.recipients = [NSArray arrayWithObjects: myNum, nil, nil]; Actually, you may not even need the two values; just the one. Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 06:45 PM (10 years ago)
So this: { "itemId": "0949A62611135A449569641", "itemType": "sw_smugmsgloc", "itemNickname": "MessageLocation", "navBarTitleText": "MessageLocation", "smugsubjdata": "Over Here!", "backgroundColor": "#999999", "hideFromSearch": "1", "smugmsgdata": "http://maps.google.com/maps?hl=en&f=d&q=[deviceLatitude],[deviceLongitude]" } Would become this: { "itemId": "0949A62611135A449569641", "itemType": "sw_smugmsgloc", "itemNickname": "MessageLocation", "navBarTitleText": "MessageLocation", "smugsubjdata": "Over Here!", "backgroundColor": "#999999", "hideFromSearch": "1", "smugmsgdata": "http://maps.google.com/maps?hl=en&f=d&q=[deviceLatitude],[deviceLongitude]", "locationPhone":"123-456-7898" } And this: picker.messageComposeDelegate = self; picker.recipients = [NSArray arrayWithObjects: nil, nil, nil, nil]; Would become this: NSString *myNum = [screenData.jsonVars objectForKey:@"locationPhone"]; picker.recipients = [NSArray arrayWithObjects: myNum, nil, nil]; where does the "myNum" come from and is there anything else to change? Thanks, Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 06:54 PM (10 years ago)
Exactly! :) "MyNum" is created here: NSString *myNum = [screenData.jsonVars objectForKey:@"locationPhone"]; It's what is known as an 'instance variable' and is used ONLY in the method it is created in. Don't forget/remove your message delegate. That will be needed too. picker.messageComposeDelegate = self; But yes, substitute this line: picker.recipients = [NSArray arrayWithObjects: nil, nil, nil]; with these lines: NSString *myNum = [screenData.jsonVars objectForKey:@"locationPhone"]; if (myNum.length < 1) myNum = nil; // in case there is no number, you don't want an error picker.recipients = [NSArray arrayWithObjects: myNum, nil, nil]; Hopefully there is nothing else to change. Try it out; if it breaks let me know and we'll keep going, lol! But that should take care of your issue, today and tomorrow. I'll consider adding an extra value in the plugin for the future. Nice idea :) Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 06:59 PM (10 years ago)
Cool, ill give it a go! Pretty handy feature to have in the plugin if i say so. just remember to name it "locationPhone". You know, so its easy for me when you update the plugin :p Thanks, Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 07:04 PM (10 years ago)
Can do will do ;) Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 07:31 PM (10 years ago)
-(void) sendSmugMsg { // Bracket 1 locksmith_appDelegate *appDelegate = (locksmith_appDelegate *)[[UIApplication sharedApplication] delegate]; if([appDelegate.rootDevice canSendSMS]){ Class smsClass = (NSClassFromString(@"MFMessageComposeViewController")); if(smsClass != nil && [MFMessageComposeViewController canSendText]){ MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]){ locksmith_appDelegate *appDelegate = (locksmith_appDelegate *)[[UIApplication sharedApplication] delegate]; BT_navController *theNavController = [appDelegate getNavigationController]; BT_viewController *theViewController = theViewController; picker.messageComposeDelegate = self; NSString *myNum = [screenData.jsonVars objectForKey:@"locationPhone"]; if (myNum.length < 1) myNum = nil; // in case there is no number, you don't want an error picker.recipients = [NSArray arrayWithObjects: myNum, nil, nil]; NSString *tmpBody = self.smugUrlData; tmpBody = [tmpBody stringByReplacingOccurrencesOfString: @"[deviceLatitude]" withString:smugLat]; tmpBody = [tmpBody stringByReplacingOccurrencesOfString: @"[deviceLongitude]" withString:smugLng]; picker.body = tmpBody; //show it [theNavController presentViewController:picker animated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil]; } } }else{ [self showAlert:@"SMS Not Available" theMessage:@"Your device cannot send SMS Messages" alertTag:01]; }//device can send text } This line (NSString *myNum = [screenData.jsonVars objectForKey:@"locationPhone"];) Is giving the error use of undeclared identifier 'screenData'. What did i miss / muck up? This is copy paste from my code. Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 07:33 PM (10 years ago)
It's probably my syntax… try 'self.screenData.jsonVars' Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 07:35 PM (10 years ago)
Yup. Now to see if it works!
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 07:41 PM (10 years ago)
Damn Smug you a genius. Its perfect :) This would work for email address too right? Thanks, Jeremy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/15/14 08:32 PM (10 years ago)
If I really were a genius I'd have gotten it right the first time ;) Yes, the same concept should apply for email as well… Cheers! -- Smug
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/15/14 08:35 PM (10 years ago)
Well, genius isn't perfect! Its about the end result. Not to mention you spurted it out on the fly! Cool :) If i need to do it for emails thats that problem sorted too! If it arises. lol Thanks, Jeremy
 
Susan Metoxen
buzztouch Evangelist
Profile
Posts: 1706
Reg: May 01, 2011
Hopkins, Minnes...
26,260
like
03/15/14 10:19 PM (10 years ago)
Smug, thank you for your help. This type of help to Buzztouch members is invaluable.
 
Jlentriken
Aspiring developer
Profile
Posts: 246
Reg: Dec 26, 2012
Palm Beach, Gol...
12,110
like
03/18/14 05:30 AM (10 years ago)
Thats what makes Buzztouch better than the rest. So much of the 'simple stuff' I've needed help for/with would have attracted mostly trolls on other forums. But here its all help. Thanks again Smug :) Jeremy
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.