archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • An iOS 8 Swift Facebook Integration Tutorial using UIActivityViewController - Techotopia
    the Constrain to margins option disabled Creating Outlets and Actions In order to create the outlets and actions for the application we will as always make use of the Assistant Editor First select the Text View object and then display the Assistant Editor Make sure that the ViewController swift file is displayed in the editor before Ctrl clicking on the Text View object in the view and dragging the resulting line to the area immediately beneath the class declaration directive in the Assistant Editor panel Upon releasing the line the configuration panel will appear Configure the connection as an Outlet named postText and click on the Connect button Repeat the above steps to add an outlet for the Image View object named postImage The application will require three actions One for each of the button objects and one for the background view that will be used to hide the keyboard when the user has finished entering text Click on the Select Image button noting that it may be necessary to click on it a second time since the first click will select the parent Toolbar view and Ctrl click and drag the resulting line to a position beneath the viewDidLoad method in the Assistant Editor In the resulting configuration panel change the Connection type to Action and name the method selectImage Repeat this step to add an action for the Post Message button this time naming the action sendPost Once the connections have been established select the ViewController swift file and further modify it to configure the class to act as an image picker delegate and to add some imports that will be required later in the tutorial import UIKit import Social import MobileCoreServices class ViewController UIViewController UIImagePickerControllerDelegate UINavigationControllerDelegate IBOutlet weak var postText UITextView IBOutlet weak var postImage UIImageView eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Implementing the selectImage and Delegate Methods The purpose of the selectImage action method is to provide the user with access to photos on the device and allow one to be selected for inclusion in the Facebook post With these requirements in mind select the ViewController swift file locate the selectImage stub added by the Assistant Editor and modify it as follows IBAction func selectImage sender AnyObject let imagePicker UIImagePickerController imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceType PhotoLibrary imagePicker mediaTypes kUTTypeImage as NSString imagePicker allowsEditing false self presentViewController imagePicker animated true completion nil Next add the other image picker delegate methods so that the picker is dismissed when the user has made a selection func imagePickerController picker UIImagePickerController didFinishPickingMediaWithInfo info NSObject AnyObject self dismissViewControllerAnimated true completion nil let image info UIImagePickerControllerOriginalImage as UIImage postImage image image func imagePickerControllerDidCancel picker UIImagePickerController self dismissViewControllerAnimated true completion nil Hiding the Keyboard When the user touches the view object in the background of the user interface we

    Original URL path: http://www.techotopia.com/index.php/An_iOS_8_Swift_Facebook_Integration_Tutorial_using_UIActivityViewController (2016-02-13)
    Open archived version from archive


  • IOS 8 Facebook and Twitter Integration using SLRequest and Swift - Techotopia
    on the device let account ACAccountStore let accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion success Bool error NSError Void in if success Get account and communicate with Twitter API In the event that access is granted an array of Twitter accounts on the device can be obtained via a subsequent call to the accountsWithAccountType method of the account object used for the request The required account may then be extracted from the array of accounts for use in constructing an SLRequest object The following code accesses the array of accounts selects the last account entry and assigns it to twitterAccount let account ACAccountStore let accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion success Bool error NSError Void in if success let arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 let twitterAccount arrayOfAccounts last as ACAccount The next task is to request an SLRequest object for Twitter access This is achieved via a call to the requestForServiceType class method of the SLRequest class passing through the following values The type of social network service for which the SLRequest will be used in this case SLServiceTypeTwitter The HTTP request method type SLRequestMethodPOST SLRequestMethodGET or SLRequestMethodDELETE The URL required by the social network API for interaction An NSDictionary object containing any parameters required by the social network API to complete the transaction The following code changes request an SLRequest instance configured for sending a Twitter update containing the text My first post from iOS 8 let account ACAccountStore let accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion success Bool error NSError Void in if success let arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 let twitterAccount arrayOfAccounts last as ACAccount let message status My first post from iOS 8 let requestURL NSURL string https api twitter com 1 1 statuses update json let postRequest SLRequest forServiceType SLServiceTypeTwitter requestMethod SLRequestMethod POST URL requestURL parameters message eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Finally the account object needs to be assigned to the SLRequest object and the request posted to the Twitter API let account ACAccountStore let accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion success Bool error NSError Void in if success let arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 let twitterAccount arrayOfAccounts last as ACAccount let message status My first post from iOS 8 let requestURL NSURL string https api twitter com 1 1 statuses update json let postRequest SLRequest forServiceType SLServiceTypeTwitter requestMethod SLRequestMethod POST URL requestURL parameters message postRequest account twitterAccount postRequest performRequestWithHandler responseData NSData urlResponse NSHTTPURLResponse error NSError Void in if let err error println Error err localizedDescription println Twitter HTTP response urlResponse statusCode For the purposes of this example the handler for the performRequestWithHandler method simply outputs the HTTP response code for the request to the console

    Original URL path: http://www.techotopia.com/index.php/IOS_8_Facebook_and_Twitter_Integration_using_SLRequest_and_Swift (2016-02-13)
    Open archived version from archive

  • An Swift iOS 8 Twitter Integration Tutorial using SLRequest - Techotopia
    ePub PDF Kindle edition contains 105 chapters Accessing the Twitter API The code to access the Twitter account and extract the posts from the account timeline will reside in a method named getTimeLine located in the ViewController swift file Select this file and modify it to add the code for this new method func getTimeLine let account ACAccountStore let accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion success Bool error NSError Void in if success let arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 let twitterAccount arrayOfAccounts last as ACAccount let requestURL NSURL string https api twitter com 1 1 statuses user timeline json let parameters screen name techotopia include rts 0 trim user 1 count 20 let postRequest SLRequest forServiceType SLServiceTypeTwitter requestMethod SLRequestMethod GET URL requestURL parameters parameters postRequest account twitterAccount postRequest performRequestWithHandler responseData NSData urlResponse NSHTTPURLResponse error NSError Void in var err NSError self dataSource NSJSONSerialization JSONObjectWithData responseData options NSJSONReadingOptions MutableLeaves error err as AnyObject if self dataSource count 0 dispatch async dispatch get main queue self tweetTableView reloadData else println Failed to access account Much of the code in this method will be familiar from the previous chapter There are however some notable exceptions First the URL used in the request is intended to return the entries in the time line for a specific user s Twitter account let requestURL NSURL string https api twitter com 1 1 statuses user timeline json The URL specified requires additional parameters specifying the Twitter user s screen name and how much data is to be returned In this case the request is limited to the 20 most recent posts and configured to include the tweet entities for a user with the screen name techotopia let parameters screen name techotopia include rts 0 trim user 1 count 20 The SLRequest object is primed to use the SLRequestMethod GET HTTP request method This is appropriate since this time we are getting as opposed to posting data let postRequest SLRequest forServiceType SLServiceTypeTwitter requestMethod SLRequestMethod GET URL requestURL parameters parameters Finally the handler code for the postRequest method call now accesses the returned NSData object The NSJSONSerialization class is then used to parse and serialize the data returned and assign it to the dataSource NSArray object The Table View object is then told to reload the data it is displaying causing it to re read the data in the dataSource array and display it to the user An important point to note here is that iOS performs the Twitter API request in a different thread from the main thread of the application Threads are the cornerstone of any multitasking operating system and can be thought of as mini processes running within a main process the purpose of which is to enable at least the appearance of parallel execution paths within applications Since user interface updates take place in the main thread of the application code has been added to ensure that the Table View reload call is made in the main thread

    Original URL path: http://www.techotopia.com/index.php/An_Swift_iOS_8_Twitter_Integration_Tutorial_using_SLRequest (2016-02-13)
    Open archived version from archive

  • Making Store Purchases in Swift with the SKStoreProductViewController Class - Techotopia
    the URL into a text editor and extract the ID from the end The ID from the following URL for example is 527049179 http itunes apple com us movie the pirates band of misfits id527049179 Alternatively searches may be performed on a variety of criteria using the Apple Search API details of which can be found at the following URL http www apple com itunes affiliates resources documentation itunes store web service search api html When the user has finished in the store view a delegate method is called to notify the application at which point the store view controller can be dismissed The remainder of this chapter will work through the creation of a simple example application to demonstrate the use and implementation of the SKStoreProductViewController class Creating the Example Project The example application created in this chapter will consist of a single button which when touched will display the store kit view controller primed with a specified product Launch Xcode and create a new project by selecting the options to create a new iOS application based on the Single View Application template Enter StoreKitDemo as the product name choose Swift as the programming language and set the Devices menu to Universal Creating the User Interface Within the project navigator panel select the Main storyboard file and drag and drop a Button from the Object Library to the center of the view Double click on the button text and change it to Buy Now so that the layout matches Figure 94 1 With the Button view selected display the Auto Layout Align menu and enable the horizontal and vertical Center in Container constraints Display the Assistant Editor and make sure it is showing the code for the ViewController swift file Select the button in the view and then Ctrl click on it and drag the resulting line to a location just beneath the viewDidLoad method in the Assistant Editor panel Release the line and in the resulting panel change the connection type to Action and name the method showStoreView Click on the Connect button and close the Assistant Editor panel Figure 94 1 eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Displaying the Store Kit Product View Controller When the user touches the Buy Now button the SKStoreProductViewController instance needs to be created configured and displayed Before writing this code however it will be necessary to declare the StoreKitDemoViewController class as implementing the SKStoreProductViewControllerDelegate protocol The StoreKit framework also needs to be imported Both of these tasks need to be performed in the ViewController swift file which should be modified to read as follows import UIKit import StoreKit class ViewController UIViewController SKStoreProductViewControllerDelegate Remaining within the ViewController swift file locate the stub showStoreView method and implement the code as outlined in the following listing IBAction func showStoreView sender

    Original URL path: http://www.techotopia.com/index.php/Making_Store_Purchases_in_Swift_with_the_SKStoreProductViewController_Class (2016-02-13)
    Open archived version from archive

  • Building In-App Purchasing into iOS 8 Swift Applications - Techotopia
    product in products Handle invalid product IDs if required Each SKProduct object will contain product information name description and price and a Boolean property indicating whether the product has associated with it downloadable content hosted on the App Store There is no SKStoreProductViewController equivalent for in app purchasing It is the responsibility of the application therefore to create and display a view where the user can review the product details which should be extracted from the SKProduct object rather than hard coded into the application code and initiate or cancel the purchase eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Accessing the Payment Queue In order to process the purchase in the event that the user decides to buy the product it will be necessary for the application to place requests on the application s payment queue The SKPaymentQueue instance is not an object that is created by the application but rather an existing object on which the application makes method calls One such method call must be made in order to assign a transaction observer object to the queue SKPaymentQueue defaultQueue addTransactionObserver self Since the payment queue continues to process requests independently of the application and even in the event that the application exits it is recommended that access to the payment queue and transaction observer object assignment takes place when the application is first launched This will ensure that the application will be notified immediately of any payment transactions that were completed after the application last exited The Transaction Observer Object The transaction observer object assigned to the payment queue can be an instance of any class within the application that implements the SKPaymentTransactionObserver protocol Compliance with the protocol involves at a minimum implementing the updatedTransactions method If the application is required to download App Store hosted content the updatedDownloads method also needs to be implemented In the event that downloads are to be performed the updatedDownloads method will be called at regular intervals providing status updates on the download progress Initiating the Purchase In order to process the purchase the application creates a payment request in the form of an SKPayment object containing the matching SKProduct object for the item this is usually just a case of using the object passed through to the productsRequest method The payment request is then placed into the SKPaymentQueue which is then responsible for communicating with the App Store to process the purchase let payment SKPayment product product SKPaymentQueue defaultQueue addPayment payment The Transaction Process The payment queue will call the updatedTransactions method on the observer object when the purchase is complete passing through as an argument an array of SKPaymentTransaction objects one for each item purchased The method will need to check the transactionState property of each transaction object to verify the success or otherwise of the payment

    Original URL path: http://www.techotopia.com/index.php/Building_In-App_Purchasing_into_iOS_8_Swift_Applications (2016-02-13)
    Open archived version from archive

  • Preparing an iOS 8 Application for In-App Purchases - Techotopia
    must have In App Purchase support enabled To register the application s explicit App ID with the iOS provisioning portal and enable In App Purchasing for that ID load the project into Xcode and select the application name target from the top of the project navigator panel From the resulting project settings panel select the Capabilities tab and locate and switch on In App Purchase support as outlined in Figure 96 1 selecting a Development Team to use for the provisioning profile if prompted to do so Figure 96 1 eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Configuring the Application in iTunes Connect Enrollment in the Apple Developer program automatically results in the creation of an iTunes Connect account using the same login credentials iTunes Connect is a web portal where developers enter tax and payment information input details about applications and track the status of those applications in terms of sales and revenues Access iTunes Connect by navigating to http itunesconnect apple com in a web browser and entering your Apple Developer program login and password details First time users should click on the Contracts Taxes and Banking link and work through the various tasks to accept Apple s terms and conditions and to input appropriate tax and banking information for the receipt of sales revenue Failure to complete these steps in advance may prevent in app purchases from working In order to test in app purchases using the sandbox feature it is first necessary to create a test user account These are the account details that will be entered on the device when testing in app purchases Within iTunes Connect click on the Users and Roles option On the Users and Roles screen select the Sandbox Testers category then click on the blue button to add a new test user When prompted enter the credentials for the test user taking care not to try to use an email address already associated with an active iTunes account Once the administrative tasks are complete select the My Apps option followed by the blue button to add a new iOS app Provide an App Name this must be a name that has not been used by another developer so may involve some trial and error and a SKU Number which can be any sequence of characters involving letters numbers hyphens underscores and periods From the Bundle ID menu select the InAppDemo Xcode iOS App ID bundle created previously Once the information has been entered click on the Create button to add the app to the portal Creating an In App Purchase Item With the application configured the next step is to add an in app purchase item to it Within iTunes Connect select the newly created app from the My Apps screen and click on the In App

    Original URL path: http://www.techotopia.com/index.php/Preparing_an_iOS_8_Application_for_In-App_Purchases (2016-02-13)
    Open archived version from archive

  • An iOS 8 Swift In-App Purchase Tutorial - Techotopia
    weak var productDescription UITextView IBOutlet weak var buyButton UIButton var product SKProduct var productID YOUR PRODUCT ID GOES HERE Note that purchase attempts will fail if the product ID specified does not match that defined for the in app purchase item created using iTunes Connect The class is also going to act as the transaction observer and products request delegate so this fact is declared Properties have been added to allow the class to keep track of the product ID and SKProduct object Storing the Home View Controller in the App Delegate Class The PurchaseViewController class is responsible for handling the purchase of access to the level 2 scene within the application As such it will be the responsibility of the PurchaseViewController to enable the Enter Level 2 button in the first view controller when a purchase has been completed This will be achieved by making a call to a method in the first view controller In order to be able to access this method a reference to the first view controller needs to be accessible to the PurchaseViewController instance For the purposes of this example this will be achieved by placing a reference to the first view controller in the application s delegate class where it can be accessed when needed within the PurchaseViewController instance Select the AppDelegate swift file and edit it to add this variable import UIKit UIApplicationMain class AppDelegate UIResponder UIApplicationDelegate var window UIWindow var homeViewController ViewController eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Completing the ViewController Class In order to complete the ViewController class implementation select the ViewController swift file and modify it to import the StoreKit framework Also code needs to be added to assign a reference to the view controller instance to the homeViewController variable previously added to the app delegate class so that it can be accessed from the PurchaseViewController import UIKit import StoreKit class ViewController UIViewController IBOutlet weak var level2Button UIButton override func viewDidLoad super viewDidLoad let appdelegate UIApplication sharedApplication delegate as AppDelegate appdelegate homeViewController self Finally implement the enableLevel2 method which will be called by the PurchaseViewController instance to enable the Level 2 access button once the purchase is complete func enableLevel2 level2Button enabled true The ViewController class is now complete Completing the PurchaseViewController Class The first steps in completing the PurchaseViewController class are to add some code to the viewDidLoad method To begin with until product information has been obtained and displayed to the user the buy button should be disabled The class also needs to be configured as the transaction observer for the purchase operation Finally a method needs to be called to obtain the product information for the purchase and display it to the user To achieve these tasks edit the PurchaseViewController swift file and modify the viewDidLoad method accordingly override func viewDidLoad super

    Original URL path: http://www.techotopia.com/index.php/An_iOS_8_Swift_In-App_Purchase_Tutorial (2016-02-13)
    Open archived version from archive

  • Configuring and Creating App Store Hosted Content for iOS 8 In-App Purchases - Techotopia
    app purchase hosted content package consists of a structured folder the root level of which must contain a ContentInfo plist file which in turn contains two keys ContentVersion The version number of the content IAPProductIdentifier The product identifier of the product with which the content is associated The folder must also contain a sub folder named Contents in which resides the content files associated with the in app purchase App Store hosted content packages are limited to 2GB in size and must not contain executable code or content that violates any of Apple s guidelines Creating an In App Purchase Hosted Content Package The easiest way to create a hosted content package is to use Xcode To do so launch Xcode and create a new project When prompted to select a template for the new project select the Other entry listed under iOS in the left hand panel of the template screen and in the main panel select In App Purchase Content as demonstrated in Figure 98 2 Figure 98 2 Click Next and on the subsequent screen enter a name for the content package which matches the product ID of the purchase item as declared in iTunes Connect Click Next and choose a location for the project before clicking on the Create button eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Within the main Xcode screen unfold the Supporting Files section of the project navigator panel and select the ContentInfo plist file Review the contents of the file and note that the version is set to 1 0 by default Since this is the first version of the content this can be left unchanged If the content is modified at any point in the future this version number should be incremented accordingly Using a Finder window locate the content files that are to be hosted on the App Store and drag and drop them onto the Supporting Files header in the Xcode project navigator panel and click Finish on the resulting panel Archiving the Hosted Content Package With the content configured the next step is to create the hosted content package file This is achieved by selecting the Xcode Product Archive menu option Once the package has been created display the Organizer window and select the Archives tab as shown in Figure 98 3 Figure 98 3 Validating the Hosted Content Package Before the package is uploaded to Apple s servers it should first be validated to ensure it does not contain ineligible content To perform the verification click on the Validate button in the Organizer window and enter your Apple developer program credentials to verify that the content meets Apple s format guidelines Xcode will then ask that the application for which the content is to be associated be selected from the drop down menu as

    Original URL path: http://www.techotopia.com/index.php/Configuring_and_Creating_App_Store_Hosted_Content_for_iOS_8_In-App_Purchases (2016-02-13)
    Open archived version from archive



  •