iOS: Programmatically Posting to HTTP and Webview

When working with mobile apps there may come a time when you need to hook your native app up to a webview.  All-in-all this is a fairly simple process but as with anything there is always a gotcha lurking around the corner.

The first snippet of code is going to show you how to make a post request in iOS using NSURLConnection.  The first thing you will want to do is set your viewcontroller as the delegate for NSURLConnection in your header file like so:

1
@interface ViewController : UIViewController <NSURLConnectionDelegate>

Typically you would then implement the delegate methods but since it would make the most sense to show you how we get to those delegate methods, I will show you that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
NSString *post = [NSString stringWithFormat: @"userName=%@&password=%@", self.userName, self.password];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:@"http://www.theurltopostto.com"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setTimeoutInterval:20.0];
[request setHTTPBody:postData];
[NSURLConnection connectionWithRequest:request delegate:self];

As you can see, we simply create a new NSMutableURLRequest and set the parameters for that request specifying a post.  Then after it is all set up we simply create a new NSURLConnection.  This is what will then call our delegate methods as this is the asynchronous way of making the HTTP callout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    _responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [_responseData appendData:data];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
                  willCacheResponse:(NSCachedURLResponse*)cachedResponse {
    return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    //Now you can do what you want with the response string from the data
    NSString* respsoneString = [NSString stringWithUTF8String:[_responseData bytes]];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    //Do something if there is an error in the connection
}

As you can see we are just appending the data as we receive it to NSMutableData instance variable.  Once we have the data you can convert it to a string or do whatever you need for the situation.

Now let’s say you want to do the same thing only throw the results into a webview.  Using our last example, we would essentially log the user in and bring them to the site after login.  This is done in almost the exact same way except instead of using NSURLConnection we use the webview.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
NSString *post = [NSString stringWithFormat: @"userName=%@&password=%@", self.userName, self.password];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:@"http://www.theurltopostto.com"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setTimeoutInterval:20.0];
[request setHTTPBody:postData];
[self.webViewMain loadRequest: request];

As you can see, it is exactly the same changing the last line of code.  This will log our user in and bring them to the appropriate page in the webview.

Like always, if you have any questions or comments, leave them below!

Posted in Technology | Tagged , | Leave a comment

Mobile March TC 2014

If you missed it, last week was time again for Mobile March.  Mobile March is a one day event dedicated to exploring the latest in mobile technology and trends which is held every year in the twin cities of MN.

Mobile March TC

This was my third year attending this conference.  Each year the event organizers manage to put together good information and have had a solid turnout.  What were some of the key pieces of information that stuck out to me from the conference?  I am always a fan of hearing the statistics of mobile and connected devices as they grow so fast it is amazing.  Here are some numbers heard throughout the conference:

  • 371,000 babies are born daily
  • 645,000 iOS devices activated
  • 1,500,000 Android devices activated
  • 7,000,000,000 people on the earth
  • 6,000,000,000 access to mobile
  • 4,500,000,000 access to toilets
  • 1,000,000,000,000 mobile-connected sensors by 2018

More devices are activated each day than babies are born in the US.  I can only assume each baby has their own mobile device as they enter this world!  Obviously I am kidding but those numbers are big.  It is also key to note that people in the world have more access to mobile devices than they do toilets.

If you have been following IoT, then you are familiar with mobile-connected sensors but you may not have known the scale of where they are going to be by 2018.  That’s a lot of devices!  The possibilities of what you can do with connected devices is big with how popular mobile devices are.  Mobile devices can then be the horsepower behind these devices.  This means they are the interface.

Another good takeaway I got from Mobile March was that mobile is the new normal.  More people are using mobile devices as their computer than ever before.  When you are thinking about how to use mobile in your business you need to reimagine how you currently do business.  Think about capabilities in your business that were once not possible but are now possible through mobile.  This can mean streamlining apps or bring services to market that have not existed before.  All of these tips are great tips but it still comes down to creativity and ideas.

That about sums up my key takeaways from Mobile March.  If you were able to attend, what were your key takeaways?  If you were not able to attend I would recommend checking it out next year.  There is always something for someone!

Posted in Technology | Tagged , , | Leave a comment

Android Wear SDK

In case you missed it, last week Google announced their preview SDK for Android Wearables.  I am sure you are wondering, what does this mean?  It means that Google has recognized the trend of wearables and sees them as being the future for mobile.

The SDK gives the developers a centralized way of programming against the Android platform to work with a number of wearable devices.  I think this is a good move towards building better standards around how we develop to all of the different devices out there.  I know for sure from my experience building Chatter Notifier that this would have not only made building the app easier but also made it so the app would work with more than just one device.

One of my favorite features built into the Wear SDK is the ability to have all notifications go through your wearable device which will also dismiss said notifications from your phone when dismissed on the device.  When the SmartWatch first came out this was the feature that I wanted the most and ended up writing an app that did just that but was rendered useless by newer versions of Android.

The future of Wear will be interesting.  If you think about it, a lot of what Glass is and does can be done through something like the Wear SDK so I’m curious if or how Glass will use it.  What do you think of the Wear SDK?

I’ll leave you with a quick video about the Wear SDK:

Posted in Technology | Tagged , , , | Leave a comment

What SEO Trends Mean for Content Professionals

The pace of change in search engine optimization (SEO) continues to accelerate. It’s quickly evolving beyond the usual tried-and-true tactics to a more sophisticated and audience-centric discipline. Consider a few posts from recent weeks:

The Moz blog did a useful before-and-after comparison of the layout and format changes to SERPs. As they point out, marketers simply need to pay attention and fine-tune their tactics:

A few dozen marketers complaining about the new design is not going to sway their decision. At this point, the decision is 98% made, and it’s made based on Google’s goals and Google’s data. The best you can do is try to assess how these changes impact your bottom line and adjust accordingly. Don’t waste your time shouting at the wind.

Meanwhile, a post over at MarketingProfs nicely summarizes how keywords are now the means to revealing user intent, why many past SEO practices simply don’t matter as much, and how writing for users is more critical than ever:

The words surrounding your keywords are now more precisely interpreted. The search engine is better able to discern the relationships between words and thus the context and the user’s intent, delivering a much more relevant search result.

What do all of these changes mean for content strategists and writers? On the Confab Events blog, James Gunter outlines what it means for our profession:

SEO is not dead. However, SEO has shifted away from a full-time specialty to a set of skills, principles, and best practices that good content creators need to know and apply in order to be successful on the web.

The last word goes to Christopher S. Penn, who issues a challenge to anyone who’s tempted by SEO tricks:

Do what’s unique. Do what’s hard to replicate, hard to scale, hard to automate. And every proposal, pitch, or offer you get that says they have an easily automated system to do X, you now know to be a trap just waiting to happen.

The evolution of SEO can seem overwhelming at times, but many resources can help. As one example: If you’re near Sundog’s Fargo office, join us for an upcoming content strategy meetup featuring a panel of SEO experts.

Posted in Technology | Tagged , , , , | Leave a comment

Salesforce – Recipe for Web-to-Content Process

Salesforce has a simple process for creating a lead from a web site.  It is called a ‘Web-to-Lead’ form.  All you need to do is…

1) Setup your Lead object with any custom fields
2) In the Setup menu under Build, Customize, Leads select the ‘Web-to-Lead’ link.
3) Click on the ‘Create Web-to-Lead Form’ button.
4) Select the fields you want captured on the Web-to-Lead form and specify a ‘Return URL’ for where the user should be directed after the form is filled out.
5) Add the generated HTML to a page in your web site.

That is all great and it is easy to plug that generated HTML into your web site so you can start capturing leads.  But what if you do not use leads?  When we look under the Contacts link in Setup we do not see a ‘Web-to-Contact’ button.

What should we do?  It really is pretty simple.  Here we go!

1) Add a custom checkbox field called ‘AutoConvert’ to the lead object.
2) When you generate your ‘Web-to-Lead’ form include this custom field in the selected fields.
3) Hit the Generate button
4) When the HTML is generated it will produce your ‘AutoConvert’ field like this

1
AutoConvert:<input  id="00NE0000005D8Oq" name="00NE0000005D8Oq" type="checkbox" value="1" /><br>

5) Change that line to be this line so that it is hidden on the page and it will always be set to true (value=“1”).  Make sure the long string in the name attribute matches.

1
<input type=hidden name="00NE0000005D8Oq" value="1">

6) Add the Web-to-Lead form to your web site and make sure that when it is submitted that it is creating a lead in your org.

As we said before we do not want a lead, but rather we want a contact.  So we need to have a trigger like the one below that will convert that Lead to a Contact when our new ‘AutoConvert’ checkbox is checked.  This checkbox will allow leads to be created in the system without having it auto convert.

Here is the trigger code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
trigger LeadConvert on Lead (after insert) {
    list<database.leadconvert> leadsToConvert = new list<database.leadconvert>();
    Database.LeadConvert lc;
    string convertedStatus ='';
    list<leadstatus> convertStatusList = new list<leadstatus>();
    convertStatusList = [Select Id, MasterLabel
                            from LeadStatus
                            where IsConverted=true limit 1];
    if(convertStatusList.size() > 0){
        convertedStatus = convertStatusList[0].MasterLabel;
    }else{
        convertedStatus ='Closed - Converted';
    }
    
    for(Lead l : trigger.New){
        if(l.AutoConvert__c == true){
            //This lead should be converted automatically to a Contact/Account
            lc = new database.LeadConvert();
            lc.setLeadId(l.ID);
            lc.setDoNotCreateOpportunity(true);
            lc.setConvertedStatus(convertedStatus);
            leadsToConvert.add(lc);
        }
    }
    
    
    list<database.leadconvertresult> lcrList = new list<database.leadconvertresult>();
    lcrList = Database.convertLead(leadsToConvert);
}
</database.leadconvertresult></database.leadconvertresult></leadstatus></leadstatus></database.leadconvert></database.leadconvert>

Now go back and try your Web-to-Lead form again.  Since the form should automatically set the new custom checkbox field ‘AutoConvert’ to true, the trigger will notice that and will automatically convert the lead to a contact.

Voila!  We have a ‘Web-to-Contact’ process.

Posted in Technology | Tagged , , , , | Leave a comment

The Importance of Mobile in a Developing World

What do you think of when you picture technology in a developing country, perhaps one in Africa? Do you picture clunky desktops, the likes of which we haven’t seen in the United States in twenty years? Maybe a rotary phone?

It might surprise you to learn that that couldn’t be further from the truth. There is a rather interesting phenomenon happening in many developing nations. They skipped advanced desktops, and even laptops, and went right to mobile. Developing nations have gone quite high-tech.

In a recent article, the Christian Science Monitor explored the many ways mobile technology has changed developing nations. Considering that much of the industry in African takes place far away from any kind of traditional office, mobile technology can help farmers and other workers communicate and have a pulse on global business. For those working in healthcare, text message reminders to AIDS patients have increased the number of people taking much needed medicine.

While this mobile revolution is still in its early phases, it is an important development for businesses across the world, and imperative to those doing business on a global level. In the United States, in other developed nations, and now, in developing nations, mobile is where more and more people are accessing your website, portals, doing B2B work, gathering information and connecting with others. If you plan to do business on any sort of a global scale, mobile is going to change everything (indeed, it already has).

How can an app change the way people interact with your brand? How can text messaging keep you connected with employees and customers, no matter where they are? Is your most important information easily accessible on a phone? Where are people located (at home, out and about, far away from towns and business) when they need to give or receive information? These are all questions you must ask yourself when making business decisions, marketing decisions, and the decisions that will guide your company into the future.

Posted in Technology | Tagged , | Leave a comment

Upcoming Community for Filmmakers

I came across this site and had to share it. Stillmotion is building a community worth paying attention to. It is a free membership centered around building local communities. It allows you to find people close by who can help make your productions come to life. Say you are strong in directing, but poor at audio, or love to shoot, but hate to edit, Story&Heart is centered around this idea of making connections with those who can compliment your strengths.

The other side of Story & Heart is their video licensing. This is how they plan to support the community and keep it free, all while helping you make a little extra cash on the footage that never made it into your final video. Stillmotion says the site should be live within two months. They have show they can produce some amazing work, I believe this site has great potential to help bring together collaborators and help build a community with your local and national talent.

Posted in Technology | Tagged , , , , , | Leave a comment

How Frequent Should Promotional Emails Be?

“I signed up for their promotional emails so I would hear about their next big sale, but they started sending me so many emails, I unsubscribed.” These were the telling words from a discussion last week about a super-sale my sister had discovered a few weeks before at a new store. She was an eager repeat customer and wanted to be notified of their next blow-out sale, but found their promotional emails so annoyingly frequent that she unsubscribed. Such is the tragic mistake of so many retailers who, in their zeal to “stay in front of customers,” end up blocking their view and annoying them instead!

Finding that happy balance is difficult because it varies from person to person. A frequency that is acceptable and even welcome to one person is a nuisance and intrusion to another. It’s time to throw out one-size-fits-all and start letting individuals determine how often and what kind of emails arrive in their inbox. What are their interests? Do they just want the featured product emails? Do they want the newsletter, too? Most likely they’ll be open to receiving more frequent emails if it’s something to which they’ve opted in. My sister, for example, only wanted to know about the next big sale, not every featured new item the store sells. Studies show that segmented emails have a much higher open and click-through rate than blanket approach emails. Read a personal experience with the success of segmented emails.

When it comes right down to it, the answer is: it depends. If you don’t have enough content, corporate size, or diversity to offer variety and choice in your emails, then err on the side of caution. Let your users tell you what they like (or didn’t like when they unsubscribe) by giving them opportunities to provide feedback. And remember, tangible incentives go a long way in eliciting responses from your audience.

Posted in Technology | Tagged , , , | Leave a comment

Customers Don’t Trust Marketers, But You Can Do Something about It

A new report is out from SDL that studies how much consumers trust marketers with their personal data. They found that, unfortunately, consumers don’t have much trust for marketers at all. 65% of people in the US worry about their information being used in marketing.

Considering recent data breaches, the prevalence of identity theft, and the general creepiness consumers feel when they realize how much brands know about them, it’s difficult to blame anyone for being nervous about sharing their information. Still, that information is vital if you want to create personalized, useful marketing campaigns. Here are some interesting findings from the study, and ways you should use that information to guide your data collection efforts.

1. People are uninformed about privacy.
The research found that few people read privacy statements on websites, or understand why companies want their data. That lack of understanding leads to distrust. What can you do about it? Explain, in easy to understand words, why you are asking for the data. Even if laws require you to explain privacy in words no one but a lawyer would understand, try to deliver that information to consumers in simplified ways too. Be ready to answer questions in person, and online. Open up a conversation about data collection so consumers know what to expect.

2. Consumers demand service no matter what.
Lots of marketers want to tell consumers that by collecting their data, they can offer a better experience. That’s fine, but that experience must be truly stellar. Customers demand great service from companies, regardless of how much data they have. Use data in ways that actually help consumers in relevant ways, in the right moment. An email for a spring sale is fine. An email to a specific part of the country about a rain boot sale just before a storm hits is even better.

3. Consumers will be much quicker to give you data if they trust you.
You have to build a relationship with customers before you deserve their data. The study sites Amazon as an excellent example of this. They have great customer service, customers have a relationship with the store because they can write reviews, get recommendations and make wish lists, and they are known for being a reliable place to shop. Because of this, people are willing to give Amazon their information. You should look to Amazon as an example. When people interact with you, make sure they have a good experience. Look for touch points where you can make someone get to know your brand. If they are willing to give you an email, can you communicate great information? Is there a portal or login on your website that people can join without offering too much, but get lots of benefits? How do you interact with customers when you don’t know anything about them? Can they see your success stories, your social interactions with others, or your customer reviews? Never barge into an interaction asking for a name, email address, phone number, physical address, and credit card information. No one will offer it to a company they don’t feel good about yet.

4. Consumers are willing to give some information, but not all.
In the study, SDL found that customers are reasonably willing to offer data like gender, date of birth, hobbies, and marital status. When it comes to information about their friends and family, their spouse’s name, and social security numbers however, they became far less willing to share. Consider this when you are gathering information. Knowing that someone is married is generally much more valuable information then knowing that a husband’s name is Steve. Likewise, you can make significant assumptions about the relationships a person has based on their gender, age and even hobbies. Don’t create a basic form that asks for all information and expect it to work. Only ask about what you absolutely need, and you know consumers are more willing to share.

While data use, data sharing and data protection are going to be issues that continue to be widely talked about in the future, there are some efforts you can make now to help grow consumers’ trust. Be smart about how, when and why you ask for information, and be sure you deserve the trust your customers have in you.

Posted in Technology | Tagged , , , | Leave a comment

Mobile Technology for the Consumer: iBeacon and NFC Explained

Since Apple’s announcement last year of iBeacon, Near Field Communications (NFC), has been cast aside by the tech media as antiquated technology. But upon closer scrutiny, there is a place for both when engaging the consumer via their mobile device.

A recent article in Digital Signate Today, and their sister publication Mobile Payments Today, explains both technologies via a BLE-vs-NFC-infographic.pdf and a more detailed white paperby Steve Gurley from Pyrim Technologies (an NFC advocate): “Comparing iBeacon to NFC is fundamentally wrong. A more appropriate scenario would be to compare Bluetooth Low Energy (BLE) to NFC as it is BLE’s feature-set that the press has mistakenly attributed to Apple’s iBeacon. Many readers may be surprised to learn that iBeacon is not a device nor is it a software application. iBeacon is nothing more than a set of services (APIs) that operate between Apple’s iOS7 operating system and iOS7-compatible apps. In essence, the iBeacon API does nothing more than enable iOS apps to recognize that they are within the wireless coverage zone of a BLE transmitter.”

“The bottom line is this; BLE and NFC are designed to serve two very different purposes:
1. BLE, like a lighthouse, is used to call a mobile app’s attention to its current surroundings so that it may initiate a pre-defined action appropriate to the given location.

2. NFC, like a telephone, is used to facilitate a one-to-one, data-oriented communication session between a person and a thing or between two NFC-equipped individuals. Although BLE and NFC are designed to serve different purposes, they can be used together to create a collaborative application.”

The white paper illustrated an example of a scenario using both technologies:

“A consumer enters a retailer. Their BLE-equipped smartphone senses a signal emanating from an in-store BLE transmitter. The consumer’s smartphone automatically employs the operating system’s BLE extension (iBeacon if it’s an iOS7 device) to evaluate the transmitter’s device ID so that it may execute the appropriate action. The ID results in a prompt to the consumer’s smartphone to display a notification that they have an offer from the retailer. The consumer removes the smartphone from their pocket and acknowledges the notification on the screen. They then choose an option on the now visible offer to save a coupon to their mobile wallet. Once saved, they shop, select the promoted item from the store shelf and use their phone to tap on its NFC-equipped shelf tag for additional savings. Once satisfied with their selection, the consumer puts the item in their basket and continues shopping. They soon pass a digital sign advertising another product that catches their attention. They tap their phone on the NFC tag affixed to the digital sign and receive detailed information about the product plus a coupon for its purchase. They then select the product from the shelf, save the coupon in their mobile wallet and then proceed to checkout.

The checkout clerk rings up the purchases and then redeems the mobile coupons by scanning the coupons’ embedded barcodes. Once the sale is complete, the consumer selects the appropriate payment card from their mobile wallet, and then touches their phone to the retailer’s payment terminal. The consumer’s payment credentials are then securely transmitted to the payment terminal via NFC and the payment transaction is sent to the payment processor for approval. Once approved, the sale is complete and the consumer leaves the building having utilized both BLE and NFC wireless communications.”

iBeacon, or more appropriately Bluetooth Low Energy (BLE), is an exciting way to engage consumers via their mobile device. But, NFC still has a useful place that complements the engagement initiated by BLE.

Posted in Technology | Tagged , , | Leave a comment