Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added UnregisterPushNotification #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ ios/build
# OS X
Icon
Thumbs.db
.DS_Store
.DS_Store
ios/DerivedData
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package com.freshplanet.nativeExtensions
import flash.events.StatusEvent;
import flash.external.ExtensionContext;
import flash.system.Capabilities;

import mx.graphics.shaderClasses.ExclusionShader;


public class PushNotification extends EventDispatcher
Expand Down Expand Up @@ -75,6 +73,14 @@ package com.freshplanet.nativeExtensions
extCtx.call("registerPush", projectId);
}
}

public function unregisterPushNotification() : void
{
if (this.isPushNotificationSupported)
{
extCtx.call("unregisterPush");
}
}

public function setBadgeNumberValue(value:int):void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Map<String, FREFunction> getFunctions() {
Log.d(TAG, "C2DMExtensionContext.getFunctions");
Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();
functionMap.put("registerPush", new C2DMRegisterFunction());
functionMap.put("unregisterPush", new C2DMUnregisterFunction());
functionMap.put("setBadgeNb", new SetBadgeValueFunction());
functionMap.put("sendLocalNotification", new LocalNotificationFunction());
functionMap.put("setIsAppInForeground", new SetIsAppInForegroundFunction());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2012 Freshplanet (http://freshplanet.com | [email protected])
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//////////////////////////////////////////////////////////////////////////////////////

package com.freshplanet.nativeExtensions;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

/**
* Register the app for push notification
*
* @author titi
*
*/
public class C2DMUnregisterFunction implements FREFunction {

private static String TAG = "c2dmUnregister";


public FREObject call(FREContext context, FREObject[] args)
{
if(Build.MANUFACTURER.equals("Amazon")) {
Log.d(TAG, "push notifications disabled on amzon devices, ignoring register");
return null;
}

Context appContext = context.getActivity().getApplicationContext();
Log.d(TAG, "C2DMUnregisterFunction.call");
try {

Intent unregistrationIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
unregistrationIntent.putExtra("app", PendingIntent.getBroadcast(appContext, 0, new Intent(), 0));
appContext.startService(unregistrationIntent);

} catch (Exception e) {
Log.e(TAG, "Error sending unregistration intent.", e);
}
return null;
}


}
Binary file modified bin/AirPushNotification.ane
Binary file not shown.
1 change: 1 addition & 0 deletions ios/AirPushNotification/AirPushNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void didRegisterForRemoteNotificationsWithDeviceToken(id self, SEL _cmd, UIAppli
void didFailToRegisterForRemoteNotificationsWithError(id self, SEL _cmd, UIApplication* application, NSError* error);
FREObject setBadgeNb(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]);
FREObject registerPush(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]);
FREObject unregisterPush(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]);
FREObject sendLocalNotification(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]);
FREObject setIsAppInForeground(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]);

Expand Down
26 changes: 20 additions & 6 deletions ios/AirPushNotification/AirPushNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
void didRegisterForRemoteNotificationsWithDeviceToken(id self, SEL _cmd, UIApplication* application, NSData* deviceToken)
{
NSString* tokenString = [NSString stringWithFormat:@"%@", deviceToken];
NSLog(@"My token is: %@", deviceToken);
//NSLog(@"My token is: %@", deviceToken);

if ( myCtx != nil )
{
Expand Down Expand Up @@ -125,6 +125,15 @@ void didReceiveRemoteNotification(id self, SEL _cmd, UIApplication* application,
return nil;
}

// unregisters the device for push notification.
DEFINE_ANE_FUNCTION(unregisterPush)
{

[[UIApplication sharedApplication] unregisterForRemoteNotifications];
return nil;
}


// register the device for push notification.
DEFINE_ANE_FUNCTION(setIsAppInForeground)
{
Expand Down Expand Up @@ -244,7 +253,7 @@ void AirPushContextInitializer(void* extData, const uint8_t* ctxType, FREContext
///////// end of delegate injection / modification code

// Register the links btwn AS3 and ObjC. (dont forget to modify the nbFuntionsToLink integer if you are adding/removing functions)
NSInteger nbFuntionsToLink = 4;
NSInteger nbFuntionsToLink = 5;
*numFunctionsToTest = nbFuntionsToLink;

FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * nbFuntionsToLink);
Expand All @@ -265,6 +274,11 @@ void AirPushContextInitializer(void* extData, const uint8_t* ctxType, FREContext
func[3].functionData = NULL;
func[3].function = &setIsAppInForeground;

func[4].name = (const uint8_t*) "unregisterPush";
func[4].functionData = NULL;
func[4].function = &unregisterPush;


*functionsToSet = func;

myCtx = ctx;
Expand All @@ -275,9 +289,9 @@ void AirPushContextInitializer(void* extData, const uint8_t* ctxType, FREContext
// Set when the context extension is created.

void AirPushContextFinalizer(FREContext ctx) {
NSLog(@"Entering ContextFinalizer()");
//NSLog(@"Entering ContextFinalizer()");

NSLog(@"Exiting ContextFinalizer()");
//NSLog(@"Exiting ContextFinalizer()");
}


Expand All @@ -290,13 +304,13 @@ void AirPushContextFinalizer(FREContext ctx) {
void AirPushExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet )
{

NSLog(@"Entering ExtInitializer()");
//NSLog(@"Entering ExtInitializer()");

*extDataToSet = NULL;
*ctxInitializerToSet = &AirPushContextInitializer;
*ctxFinalizerToSet = &AirPushContextFinalizer;

NSLog(@"Exiting ExtInitializer()");
//NSLog(@"Exiting ExtInitializer()");
}

void AirPushExtFinalizer(void *extData) { }