1 # iOS tutorial 1: Link against GStreamer
7 The first iOS tutorial is simple. The objective is to get the GStreamer
8 version and display it on screen. It exemplifies how to link against the
9 GStreamer library from Xcode using objective-C.
13 The tutorials code are in the
14 [gst-docs](https://cgit.freedesktop.org/gstreamer/gst-docs/) in the
15 `tutorials/xcode iOS` folder.
17 It was created using the GStreamer Single View
18 Application template. The view contains only a `UILabel` that will be
19 used to display the GStreamer's version to the user.
23 The UI uses storyboards and contains a single `View` with a centered
24 `UILabel`. The `ViewController` for the `View` links its
25 `label` variable to this `UILabel` as an `IBOutlet`.
30 #import <UIKit/UIKit.h>
32 @interface ViewController : UIViewController {
33 IBOutlet UILabel *label;
36 @property (retain,nonatomic) UILabel *label;
41 ## The GStreamer backend
43 All GStreamer-handling code is kept in a single Objective-C class called
44 `GStreamerBackend`. In successive tutorials it will get expanded, but,
45 for now, it only contains a method to retrieve the GStreamer version.
47 The `GStreamerBackend` is made in Objective-C so it can take care of the
48 few C-to-Objective-C conversions that might be necessary (like `char
49 *` to `NSString *`, for example). This eases the usage of this class by
50 the UI code, which is typically made in pure Objective-C.
51 `GStreamerBackend` serves exactly the same purpose as the JNI code in
52 the [](tutorials/android/index.md).
54 **GStreamerBackend.m**
57 #import "GStreamerBackend.h"
61 @implementation GStreamerBackend
63 -(NSString*) getGStreamerVersion
65 char *version_utf8 = gst_version_string();
66 NSString *version_string = [NSString stringWithUTF8String:version_utf8];
68 return version_string;
74 The `getGStreamerVersion()` method simply calls
75 `gst_version_string()` to obtain a string describing this version of
76 GStreamer. This [Modified
77 UTF8](http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8) string is then
78 converted to a `NSString *` by ` NSString:stringWithUTF8String `and
79 returned. Objective-C will take care of freeing the memory used by the
80 new `NSString *`, but we need to free the `char *` returned
81 by `gst_version_string()`.
83 ## The View Controller
85 The view controller instantiates the GStremerBackend and asks it for the
86 GStreamer version to display at the label. That's it!
91 #import "ViewController.h"
92 #import "GStreamerBackend.h"
94 @interface ViewController () {
95 GStreamerBackend *gst_backend;
100 @implementation ViewController
107 // Do any additional setup after loading the view, typically from a nib.
108 gst_backend = [[GStreamerBackend alloc] init];
110 label.text = [NSString stringWithFormat:@"Welcome to %@!", [gst_backend getGStreamerVersion]];
113 - (void)didReceiveMemoryWarning
115 [super didReceiveMemoryWarning];
116 // Dispose of any resources that can be recreated.
124 This ends the first iOS tutorial. It has shown that, due to the
125 compatibility of C and Objective-C, adding GStreamer support to an iOS
126 app is as easy as it is on a Desktop application. An extra Objective-C
127 wrapper has been added (the `GStreamerBackend` class) for clarity, but
128 calls to the GStreamer framework are valid from any part of the
131 The following tutorials detail the few places in which care has to be
132 taken when developing specifically for the iOS platform.
134 It has been a pleasure having you here, and see you soon!
136 [screenshot]: images/tutorials/ios-link-against-gstreamer-screenshot.png