iOS Question unbalanced #End If , after inline #If OBJC

le_toubib

Active Member
Licensed User
Longtime User
hi
i got the "unbalanced #end If" (at the last line)
after inserting the following code at the end of my project
#If OBJC
/*
* ------------------------------------------------------------------------------------------
* BEGIN APNS CODE
* ------------------------------------------------------------------------------------------
*/

/**
* Fetch and Format Device Token and Register Important Information to Remote Server
*/
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

#if !TARGET_IPHONE_SIMULATOR

// Get Bundle Info for Remote Registration (handy if you have more than one app)
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:mad:"CFBundleDisplayName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:mad:"CFBundleVersion"];

// Check what Notifications the user has turned on. We registered for all three, but they may have manually disabled some or all of them.
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

// Set the defaults to disabled unless we find otherwise...
NSString *pushBadge = @"disabled";
NSString *pushAlert = @"disabled";
NSString *pushSound = @"disabled";

// Check what Registered Types are turned on. This is a bit tricky since if two are enabled, and one is off, it will return a number 2... not telling you which
// one is actually disabled. So we are literally checking to see if rnTypes matches what is turned on, instead of by number. The "tricky" part is that the
// single notification types will only match if they are the ONLY one enabled. Likewise, when we are checking for a pair of notifications, it will only be
// true if those two notifications are on. This is why the code is written this way
if(rntypes == UIRemoteNotificationTypeBadge){
pushBadge = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeAlert){
pushAlert = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeSound){
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){
pushBadge = @"enabled";
pushAlert = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){
pushBadge = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
pushAlert = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
pushBadge = @"enabled";
pushAlert = @"enabled";
pushSound = @"enabled";
}

// Get the users Device Model, Display Name, Unique ID, Token & Version Number
UIDevice *dev = [UIDevice currentDevice];
NSString *deviceUuid = dev.uniqueIdentifier;
NSString *deviceName = dev.name;
NSString *deviceModel = dev.model;
NSString *deviceSystemVersion = dev.systemVersion;

// Prepare the Device Token for Registration (remove spaces and < >)
NSString *deviceToken = [[[[devToken description]
stringByReplacingOccurrencesOfString:mad:"<"withString:mad:""]
stringByReplacingOccurrencesOfString:mad:">" withString:mad:""]
stringByReplacingOccurrencesOfString: @" " withString: @""];

// Build URL String for Registration
// !!! CHANGE "www.mywebsite.com" TO YOUR WEBSITE. Leave out the http://
// !!! SAMPLE: "secure.awesomeapp.com"
NSString *host = @"www.mywebsite.com";

// !!! CHANGE "/apns.php?" TO THE PATH TO WHERE apns.php IS INSTALLED
// !!! ( MUST START WITH / AND END WITH ? ).
// !!! SAMPLE: "/path/to/apns.php?"
NSString *urlString = [@"/apns.php?"stringByAppendingString:mad:"task=register"];

urlString = [urlString stringByAppendingString:mad:"&appname="];
urlString = [urlString stringByAppendingString:appName];
urlString = [urlString stringByAppendingString:mad:"&appversion="];
urlString = [urlString stringByAppendingString:appVersion];
urlString = [urlString stringByAppendingString:mad:"&deviceuid="];
urlString = [urlString stringByAppendingString:deviceUuid];
urlString = [urlString stringByAppendingString:mad:"&devicetoken="];
urlString = [urlString stringByAppendingString:deviceToken];
urlString = [urlString stringByAppendingString:mad:"&devicename="];
urlString = [urlString stringByAppendingString:deviceName];
urlString = [urlString stringByAppendingString:mad:"&devicemodel="];
urlString = [urlString stringByAppendingString:deviceModel];
urlString = [urlString stringByAppendingString:mad:"&deviceversion="];
urlString = [urlString stringByAppendingString:deviceSystemVersion];
urlString = [urlString stringByAppendingString:mad:"&pushbadge="];
urlString = [urlString stringByAppendingString:pushBadge];
urlString = [urlString stringByAppendingString:mad:"&pushalert="];
urlString = [urlString stringByAppendingString:pushAlert];
urlString = [urlString stringByAppendingString:mad:"&pushsound="];
urlString = [urlString stringByAppendingString:pushSound];

// Register the Device Data
// !!! CHANGE "http" TO "https" IF YOU ARE USING HTTPS PROTOCOL
NSURL *url = [[NSURL alloc] initWithScheme:mad:"https" host:host path:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"Register URL: %@", url);
NSLog(@"Return Data: %@", returnData);

#endif
}

/**
* Failed to Register for Remote Notifications
*/
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

#if !TARGET_IPHONE_SIMULATOR

NSLog(@"Error in registration. Error: %@", error);

#endif
}

/**
* Remote Notification Received while application was open.
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

#if !TARGET_IPHONE_SIMULATOR

NSLog(@"remote notification: %@",[userInfo description]);
NSDictionary *apsInfo = [userInfo objectForKey:mad:"aps"];

NSString *alert = [apsInfo objectForKey:mad:"alert"];
NSLog(@"Received Push Alert: %@", alert);

NSString *sound = [apsInfo objectForKey:mad:"sound"];
NSLog(@"Received Push Sound: %@", sound);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

NSString *badge = [apsInfo objectForKey:mad:"badge"];
NSLog(@"Received Push Badge: %@", badge);
application.applicationIconBadgeNumber = [[apsInfo objectForKey:mad:"badge"] integerValue];

#endif
}

/*
* ------------------------------------------------------------------------------------------
* END APNS CODE
* ------------------------------------------------------------------------------------------
*/

#End If

is it related to the #ifs inside the inline code ? how to fix it ?
 

stevel05

Expert
Licensed User
Longtime User
If the code posted is accurate, you have a number of #endif statements, they need to be #End If, with a space. That causes the error you describe.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
As you can probably tell, I'm not up to speed with Objective C, but it appears the similarities may be conflicting with the B4i parser.

Perhaps someone has come across this before.
 
Last edited:
Upvote 0

le_toubib

Active Member
Licensed User
Longtime User
in the push notification tutorial it s very explanined how to connect with our b4j push server , but what if i need another server ... say a hosted php script ?
 
Upvote 0
Top