Is it me or xcode… Somethings wrong with my braces and it just causes errors! Please help! iPhone SDK + Urban Push

徘徊边缘 提交于 2020-01-03 04:21:16

问题


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 

回答1:


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:

}



回答2:


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;
}
}


来源:https://stackoverflow.com/questions/3411650/is-it-me-or-xcode-somethings-wrong-with-my-braces-and-it-just-causes-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!