views:

129

answers:

3

Help! I cant find whats wrong. My code is up and mostly running and i needed to incorporate Urban Air push notification and there is something wrong with my code. If there is a better or different way to incorporate this that works without my errors I would appreciate that. I took this code from a tut of Urban Airmail. I wasnt sure what to inlude and what not to from the sample app. Now for my code. Ill notate where I get errors They are stray / errors and expected ; b4 : errors

If you could fix the code that would be awesome!

    //
//  SuperSlickAppDelegate.m
//  SuperSlick
//
//  Created by  on 8/2/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h> 
#import "SuperSlickAppDelegate.h"
#import "SuperSlickViewController.h"
#import "Reachability.h"




@implementation SuperSlickAppDelegate

@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
#define kApplicationKey @"rnftzaemRp2HJMsNjwZvGQ"
#define kApplicationSecret @"X1XdTjdWQIaL72e-gXew5A"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    // Override point for customization after application launch.
    Reachability *r = [Reachability reachabilityWithHostName:@"google.com"];

    NetworkStatus internetStatus = [r currentReachabilityStatus];

    if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
    {
        UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network to use this! Try the settings app for WiFi Connectivity." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [myAlert show];
        [myAlert release];
    }



    //Register for notifications
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];
     //ERROR HERE in line above Stray 357

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
        //ERROR HERE Wrong type argument to unary minus + stray

        // Get a hex string from the device token with no spaces or < >
        self.deviceToken = [[[[_deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
                             stringByReplacingOccurrencesOfString:@">" withString:@""]
                            stringByReplacingOccurrencesOfString: @" " withString: @""];

        NSLog(@"Device Token: %@", self.deviceToken);

        if ([application enabledRemoteNotificationTypes] == 0) {
            NSLog(@"Notifications are disabled for this application. Not registering with Urban Airship");
            return;
        }

        // this is straight out of the UA sample code
        NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
        NSString *UAServer = @"https://go.urbanairship.com";
        NSString *urlString = [NSString stringWithFormat:@"%@%@%@/", UAServer, @"/api/device_tokens/", self.deviceToken];
        NSURL *url = [NSURL URLWithString:  urlString];
        ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
        request.requestMethod = @"PUT";

        // Authenticate to the server
        request.username = kApplicationKey;
        request.password = kApplicationSecret;

        [request setDelegate:self];
        [request setDidFinishSelector: @selector(registrationSuccessMethod:)]; // if you want to do something with the token
        [request setDidFailSelector: @selector(requestWentWrong:)];
        [queue addOperation:request];
    }

    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error {
        NSLog(@"Failed to register with error: %@", error);
    }

    - (void)requestWentWrong: (ASIHTTPRequest *)request {

        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        NSError *_error = [request error];

        NSLog(@"ERROR: NSError query result: %@", _error);

        UIAlertView *someError = [[UIAlertView alloc] initWithTitle:
                                  @"Network error" message: NSLocalizedString( @"Error registering with notifiction server",
                                                                              @"Error registering with notifiction server")
                                                           delegate: self
                                                  cancelButtonTitle: @"OK"
                                                  otherButtonTitles: nil];
        [someError show];
        [someError release];
    }
    // Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}
}



- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end

New Code that has troubles:

    //Register for notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)]; 
    ;}}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
    //ERROR HERE Wrong type argument to unary minus and semi colon b4 
+3  A: 

Doesn't look like you ever ended your application:didFinishLaunchingWithOptions: method - you should have an end brace after this line:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes...

So it should look like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    ...

     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];
     //ERROR HERE in line above Stray 357
}

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {

    ...

}

That should do it.

For your second code block - without seeing the surrounding code it's difficult to see what you're trying to do...you likely shouldn't have:

;}}

It should probably just be:

}
codykrieger
I need 15 rep. Sorry! Will do it asap!
Sum
Here let me paste the error lines //Register for notifications [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)]; ;}} -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken { //ERROR HERE Wrong type argument to unary minus and semi colon b4
Sum
Ill put it in the original post too!
Sum
Well those are just extra braces to close extra ones i created. Those arent the problem! Should I have to declare DeviceToken somewhere becuase xcode keeps saying devicetToken is not in organized stack...Thanks for the help!
Sum
+1  A: 

If you are looking for unbalanced parentheses, then this is probably the part that is giving you troubles:

    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}
}
kiamlaluno
+1  A: 

Thanks guys I will try it now. No matter what I do it keeps returning errors +1 for you !

sum