phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.31k stars 996 forks source link

Push Notification on Working on ios8 but its working in ios7 #340

Open mayurloved opened 10 years ago

mayurloved commented 10 years ago

Hello Thanks for such plugin but I am not able to use plugin in ios8. Even Device Register is also not working Here is my code.

Here is the Code Of PushPlugin.m

/*

Copyright 2009-2011 Urban Airship Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without

modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this

    list of conditions and the following disclaimer.

  2. Redistributions in binaryform must reproduce the above copyright notice,

    this list of conditions and the following disclaimer in the documentation

    and/or other materials provided withthe distribution.

    THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC``AS IS'' AND ANY EXPRESS OR

    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO

    EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,

    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE

    OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF

    ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    */

    import "PushPlugin.h"

@implementation PushPlugin

@synthesize notificationMessage;

@synthesize isInline;

@synthesize callbackId;

@synthesize notificationCallbackId;

@synthesize callback;

{

self.callbackId = command.callbackId;

NSMutableDictionary* options = [command.arguments objectAtIndex:0];

UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone;

id badgeArg = [options objectForKey:@"badge"];

id soundArg = [options objectForKey:@"sound"];

id alertArg = [options objectForKey:@"alert"];
if ([badgeArg isKindOfClass:[NSString class]])
{
    if ([badgeArg isEqualToString:@"true"]) {
        notificationTypes |= UIRemoteNotificationTypeBadge;
    }
}
else if ([badgeArg boolValue]) {
    notificationTypes |= UIRemoteNotificationTypeBadge;
}
if ([soundArg isKindOfClass:[NSString class]])
{
    if ([soundArg isEqualToString:@"true"]) {
        notificationTypes |= UIRemoteNotificationTypeSound;
    }
}
else if ([soundArg boolValue]) {
    notificationTypes |= UIRemoteNotificationTypeSound;
}
if ([alertArg isKindOfClass:[NSString class]])
{
    if ([alertArg isEqualToString:@"true"]) {
        notificationTypes |= UIRemoteNotificationTypeAlert;
    }
}
else if ([alertArg boolValue]) {
    notificationTypes |= UIRemoteNotificationTypeAlert;
}

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                         |UIRemoteNotificationTypeSound
                                                                                         |UIRemoteNotificationTypeAlert) categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge  | UIRemoteNotificationTypeSound];
}

   self.callback = [options objectForKey:@"ecb"];

if (notificationTypes == UIRemoteNotificationTypeNone)

    NSLog(@"PushPlugin.register: Push notification type is set to none");

isInline = NO;
if (notificationMessage)     // if there is a pending startup notification

    [self notificationReceived];    // go ahead and process it

}

/*

// Get Bundle Info for Remote Registration (handy if you have more than one app)

[results setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] forKey:@"appName"];

[results setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"appVersion"];

// 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";

}

if(rntypes & UIRemoteNotificationTypeAlert) {

    pushAlert = @"enabled";

}

if(rntypes & UIRemoteNotificationTypeSound) {

    pushSound = @"enabled";

}

[results setValue:pushBadge forKey:@"pushBadge"];

[results setValue:pushAlert forKey:@"pushAlert"];

[results setValue:pushSound forKey:@"pushSound"];

// Get the users Device Model, Display Name, Token & Version Number

UIDevice *dev = [UIDevice currentDevice];

[results setValue:dev.name forKey:@"deviceName"];

[results setValue:dev.model forKey:@"deviceModel"];

[results setValue:dev.systemVersion forKey:@"deviceSystemVersion"];

[self successWithMessage:[NSString stringWithFormat:@"%@", token]];

endif

}

{

[self failWithMessage:@"" withError:error];

}

}

// reentrant method to drill down and surface all sub-dictionaries' key/value pairs into the top level json

-(void)parseDictionary:(NSDictionary )inDictionary intoJSON:(NSMutableString )jsonString

{

NSArray         *keys = [inDictionary allKeys];

NSString        *key;

for (key in keys)

{

    id thisObject = [inDictionary objectForKey:key];

    if ([thisObject isKindOfClass:[NSDictionary class]])

        [self parseDictionary:thisObject intoJSON:jsonString];

    else if ([thisObject isKindOfClass:[NSString class]])

        [jsonString appendFormat:@"\"%@\":\"%@\",",

         key,

         [[[[inDictionary objectForKey:key]

            stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"]

           stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]

          stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]];

    else {

        [jsonString appendFormat:@"\"%@\":\"%@\",", key, [inDictionary objectForKey:key]];

    }

}

}

}

-(void)successWithMessage:(NSString *)message

{

if (self.callbackId != nil)

{

    CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];

    [self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId];

}

}

-(void)failWithMessage:(NSString )message withError:(NSError )error

{

NSString        *errorMessage = (error) ? [NSString stringWithFormat:@"%@ - %@", message, [error localizedDescription]] : message;

CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMessage];

[self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId];

} @end

hirbod commented 10 years ago

https://github.com/phonegap-build/PushPlugin/pull/317