Sebbie
Sebbie

Reputation: 91

Xcode Assistance with Coding

I am trying to figure out how to do an extension for a html file. I'm new to coding and Xcode and trying to create an app but I have enough experience in coding to understand what goes where and why.

The problem I'm facing is that I need to add an extension to a html file; example

(index.html?lc=uk) instead of (index.html).

I've created a interface and all the other information required but I can't seem to get this part to work. The coding I'm using on the ViewController.m is;

[super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"354"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];

I've tried adding to the (pathForResource) @"index.html?lc=uk" but when I test the app it doesn't work and gives me an error.

Can someone give me a idea on what I need to do?

Kind Regards,

Seb

[Log Files]

2015-06-22 12:48:53.845 UST Demo[3999:1153643] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(
    0   CoreFoundation                      0x008d0746 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x00559a97 objc_exception_throw + 44
    2   CoreFoundation                      0x008d066d +[NSException raise:format:] + 141
    3   Foundation                          0x0010edfe -[NSURL(NSURL) initFileURLWithPath:] + 139
    4   Foundation                          0x0010ed58 +[NSURL(NSURL) fileURLWithPath:] + 68
    5   UST Demo                            0x000768d5 -[ViewController viewDidLoad] + 213
    6   UIKit                               0x00df3da4 -[UIViewController loadViewIfRequired] + 771
    7   UIKit                               0x00df4095 -[UIViewController view] + 35
    8   UIKit                               0x00ce5e85 -[UIWindow addRootViewControllerViewIfPossible] + 66
    9   UIKit                               0x00ce634c -[UIWindow _setHidden:forced:] + 287
    10  UIKit                               0x00ce6648 -[UIWindow _orderFrontWithoutMakingKey] + 49
    11  UIKit                               0x0c5c9028 -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 77
    12  UIKit                               0x00cf49b6 -[UIWindow makeKeyAndVisible] + 80
    13  UIKit                               0x00c89ed8 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3217
    14  UIKit                               0x00c8d422 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1639
    15  UIKit                               0x00ca693e __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
    16  UIKit                               0x00c8c04a -[UIApplication workspaceDidEndTransaction:] + 155
    17  FrontBoardServices                  0x03232c9e __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
    18  FrontBoardServices                  0x0323272f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    19  FrontBoardServices                  0x03244d7c __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 30
    20  CoreFoundation                      0x007f2050 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
    21  CoreFoundation                      0x007e7963 __CFRunLoopDoBlocks + 195
    22  CoreFoundation                      0x007e77bb __CFRunLoopRun + 2715
    23  CoreFoundation                      0x007e6a5b CFRunLoopRunSpecific + 443
    24  CoreFoundation                      0x007e688b CFRunLoopRunInMode + 123
    25  UIKit                               0x00c8ba02 -[UIApplication _run] + 571
    26  UIKit                               0x00c8f106 UIApplicationMain + 1526
    27  UST Demo                            0x00076dfa main + 138
    28  libdyld.dylib                       0x02c5cac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

[Da Maex]

[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"354"];
path = [NSString stringWithFormat:@"%@?lc=uk", path]; // add the '?lc=uk'
NSURL *url = [NSURL URLWithString:path]; // build URL with string
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

When I've added this code I get this error

int main(int argc, char * argv[]) {
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}

}

Upvotes: 0

Views: 50

Answers (1)

Da Maex
Da Maex

Reputation: 481

If i get you right, you need to change the NSString* path like this:

path = [NSString stringWithFormat:@"%@?lc=uk", path];

But if never tried this for a local Path ([NSURL fileURLWithPath:path];) maybe you should use [NSURL URLWithString:path];? Do you have the HTML-File as resource or are you trying to access a remote source?

For a local source the GET-Parameter is eventually even not taken in account, cause there is no PHP or whatever installed as processor for the HTML file.

edit:

your Source:

[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"354"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

new Source:

[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"354"];
path = [NSString stringWithFormat:@"%@?lc=uk", path]; // add the '?lc=uk'
NSURL *url = [NSURL URLWithString:path]; // build URL with string
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

I hope this will help you.

Upvotes: 1

Related Questions