ifrit05, i'll look in to that. I'm still learning. Lots of documentation to dig through.
KawaiiAurora, Just for you i've attached a new build with safari 5 user agent to tide you over until i figure out how to add a menu item or preference pane to change user agents. Currently i can only do it manually and then recompile the browser.
On a side note i've updated my first post again. New build (1.4) now has app icon, and changed user agent to iPhone 3 as it works better on sites like facebook and twitter than the iPhone 7 user agent did.
Cheers
Hey wicknix, great to see continuing development of your browser!
Feel free to ignore if you want to take a different approach, but here's a basic user agent option strategy which could work;
1. Add an "Options" menu to MainMenu.nib in IB, with a "User Agent" submenu, then checkable menu item options like "Safari 5", "iPhone 7", "iPhone 3", etc
2. Add an ivar to your Window/Browser Controller.
NSString *userAgent;
3. Write an instance method on your Window/Browser Controller class for the option menu items to target.
Code:
- (IBOutlet) setUserAgent:(id) sender
{
if([[sender title] isEqualTo:@"Safari 5"]) {
userAgent = @"...Safari 5 user agent string...";
} else if ([[sender title] isEqualTo:@"iPhone 7"]) {
userAgent = @"...iPhone 7 user agent string...";
} else if ([[sender title] isEqualTo:@"iPhone 3"]) {
userAgent = @"...iPhone3 user agent string...";
}
//enumerate the "User Agent" submenu items to mark each option as unchecked
NSArray *userAgentMenuItems = [[[sender parentItem] submenu] itemArray];
NSEnumerator *menuEnum = [userAgentMenuItems objectEnumerator];
NSMenuItem *menuItem;
while(menuItem = [menuEnum nextObject]) {
[menuItem setState:NSOffState];
}
//then check the selected option
[sender setState:NSOnState];
}
4. Use IB to connect each of the "User Agent" options to this
setUserAgent selector as a target action.
5. Then when loading the page in your WebView, refer to your
userAgent ivar as the user agent string.
You should be able to save the setting to your app's prefs file with;
[[NSUserDefaults standardUserDefaults] setObject:userAgent forKey: @"UserAgent"];
and read with;
userAgent = [[NSUserDefaults standardUserDefaults] objectForKey: @"UserAgent"];
To implement the visual persistence of the settings, try finding your options menu item with something like
[[[NSApp mainMenu] itemWithTitle: @"Options"] in
applicationDidFinishLaunching:, drill down into the "User Agent" submenu and then set the checked state on the selected option based on the
userAgent string read in from your prefs.
-AphoticD